Destructors are not automatically virtual

A class must have a virtual destructor if it has any virtual functions, or if it is deleted through a polymorphic pointer. Destructors are not automatically virtual in classes that have other virtual functions. If you delete such a class through a pointer to one of its bases, the derived class destructors are not called unless the destructor is virtual. So, as with any other member function that you want to call through a base class pointer, the destructor must be virtual if you want the right one to be called.

Remember also that any virtual functions called from a constructor or destructor resolve to the implementation of the class whose constructor or destructor is being executed. This is because any derived class' state has not yet been constructed or has already been destructed. For more information, see "Base class constructors cannot call virtual functions" on page 96.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker