Yes , the order of destruction is always opposite to the order of construction.
Please Look at the following code .
class Base
{
public:
Base ( )
{
cout << "Inside Base constructor" << endl;
}
~Base ( )
{
cout << "Inside Base destructor" << endl;
}
};
class Derived : public Base
{
public:
Derived ( )
{
cout << "Inside Derived constructor" << endl;
}
~Derived ( )
{
cout << "Inside Derived destructor" << endl;
}
};
void main( )
{
Derived x;
}
If you run this code you will get following output.
Inside Base constructor
Inside Derived constructor
Inside Derived destructor
Inside Base destructor