#include using namespace std; class foo { int *a; public: foo() { a = new int[5]; cout << "\n foo constructor" << endl; } ~foo() { cout << "\n foo destructor" << endl; delete[] a; } }; class bar : public foo { int *b; public: bar() { b = new int[5]; cout << "\n bar constructor" << endl; } ~bar() { cout << "\n bar destructor" << endl; delete[] b; } }; int main() { foo *obj = new bar; // Derived class object is type compatible with base class delete obj; // Equivalent to obj->~foo(); getchar(); return 0; }