You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

When the destructor is called on an object of a class that is part of a class hierarchy, the destructors of both the derived and base class will be called (in that order). However, if the derived class is referenced by a pointer of a type higher up the inheritance hierarchy, then the derived class's destructor will not be called. This can result in unintended program behavior. To ensure the correct destructor is called, destructors should be declared as virtual.

Non-Compliant Code Example

Compliant Solution

  • No labels