There is a trick to do this, it involves virtual inheritence from a
base class that only you have been given access to the constructor.
The idea is that the most derived class must initialize all virtual
base classes, so if anyone inherits from you, they will not be able to
call the constructor of the base.
However, I ask why you want to do this? No C++ compiler that I am
aware of will determine that this class is final, and optimize virtual
function calls. You can signal to the user that you intend for this
class to be final by using other techniques, like making the
destructor private and providing a destroy method. Finally, if the
class has no virtual methods, by making the destructor public and
non-virtual, you have signalled to the consumer that this class is not
intended to be used as a base class.
I'm sure others will post the exact code to implement the virtual base
class technique that I described.
factset research systems
> I wish to implement a class in c++ which is equivalent to final
> classes in Java (Classes whose objects can be created but can't be
> derived/ extended from).
> Eagerly waiting for tips/ solution ....
> -Harmeet Singh
[ about comp.lang.c++.moderated. First time posters: do this! ]