/* 1. The order in which the constructors are called match the order
in which the newly created class inherits them.
2. The destructors are called in the reverse order
3. The newly created class' constructor is last to be called
4. The newly created class' destructor is the first to be called
*/
#include
class Base_1
{
public:
Base_1() { cout << "Base_1 constructor called" << endl; }
~Base_1() { cout << "Base_1 destructor called" << endl; }
};
class Base_2
{
public:
Base_2() { cout << "Base_2 constructor called" << endl; }
~Base_2() { cout << "Base_2 destructor called" << endl; }
};
class Derived :public Base_1, public Base_2
{
public:
Derived() { cout << "Derived constructor called" << endl << endl;}
~Derived() { cout << "Derived destructor called" << endl;}
};
void main()
{
Derived D;
}
/*
Base_1 constructor called
Base_2 constructor called
Derived constructor called
Derived destructor called
Base_2 destructor called
Base_1 destructor called
Press any key to continue
*/
Go Back