New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1074 - Forbid the creation of PlainObjectBase object
Forbid the creation of PlainObjectBase object
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
3.3 (current stable)
All All
: Normal API Change
Assigned To: Nobody
:
Depends on:
Blocks: 3.3
  Show dependency treegraph
 
Reported: 2015-09-28 14:00 UTC by Gael Guennebaud
Modified: 2015-12-09 20:37 UTC (History)
4 users (show)



Attachments

Description Gael Guennebaud 2015-09-28 14:00:31 UTC
It is currently possible to directly create PlainObjectBase<Derived> objects, which is not very good practice as this class has been thought as an abstract base class.

So what about disabling this possibility by making all PlainObjectBase<Derived> private, and making Derived a friend class of PlainObjectBase<Derived>?


See also the following thread for some weird usages of PlainObjectBase<Derived>: https://forum.kde.org/viewtopic.php?f=74&t=128414&p=342621
Comment 1 Christoph Hertzberg 2015-09-28 14:54:47 UTC
I also see no legit use of directly creating a PlainObjectBase<> (nor any other ...Base<>-object -- which in many cases would be an empty object, which behaves as if it contained data).
To implement this, wouldn't it be sufficient to make all constructors (and destructors, if needed) protected? Of course, this would leave the possibility to inherit 

  class WeirdClass : PlainObjectBase<SomeOtherClass> { ... };

but we can't avoid every possibility to shoot oneself in the foot ...
Comment 2 Gael Guennebaud 2015-09-28 15:04:43 UTC
yes, making them protected is definitely enough!
Comment 3 Nathan 2015-10-04 17:23:46 UTC
What about making the destructor of PlainObjectBase<typename> a pure virtual function? This would need only two additional lines of code and no changes to any of the derived classes.
Comment 4 Christoph Hertzberg 2015-12-08 17:40:26 UTC
We use pure static polymorphism in Eigen (no virtual functions).
A pure virtual destructor is actually rather complicated (I was surprised that it is even possible ...)
Comment 5 Gael Guennebaud 2015-12-09 20:37:32 UTC
https://bitbucket.org/eigen/eigen/commits/9eea85f21eed/

Note You need to log in before you can comment on or make changes to this bug.