// This example shows the order in which the constructors and destructors get
// invoked in a class hierarcy
#include
class A {
public:
A();
~A();
};
class B : public A {
public:
B();
~B();
};
class C : public B {
public :
C();
~C();
};
A::A() { cout << "Inside the constructor of A" << endl; }
B::B() { cout << "Inside the constructor of B" << endl; }
C::C() { cout << "Inside the constructor of C" << endl; }
A::~A() { cout << "Inside the destructor of A" << endl; }
B::~B() { cout << "Inside the destructor of B" << endl; }
C::~C() { cout << "Inside the destructor of C" << endl; }
int main () {
A a;
B b;
C c;
}
See the output of the above program