"Mohammad" <mj*******@hotm ail.com> wrote in message
news:3d******** *************** **@posting.goog le.com...
Is there way to write a C++ class so that it cannot be subclassed?
There is, but it's unfortunately excessively complicated,
making it inconvenient to use.
It can be done by using virtual inheritance:
// class with private constructor and destructor
class Locker {
friend NotToBeSubclass ed;
Locker() {};
~Locker() {};
};
class NotToBeSubclass ed : virtual Locker
{
//... whatever
};
The trick is: a most-derived class must call the constructor
of all virtual base classes of its parents. But the private
constructor of 'Locker' is only accessible to the
'NotToBeSubclas sed' class, which therefore cannot
be derived from.
hth, Ivan
--
http://ivan.vecerina.com