Multiple Inheritance with examples in C++

In C++ we have another great feature called inheritance. Inheritance is the derived class that can acquire the features of a base class.

Multiple inheritance:

A class that can inherit from more than one class is called multiple inheritance. In multiple inheritance, the order of constructor calls is the order that they are inherited.

Let us see the below example that helps us to understand the order of constructors.


Output of the above program is:

The destructors are called in reverse order of constructors.

We can observe that the calling of the constructer starts at the base class.
So each level the base class constructor is called first, followed by the member object constructors.

Coming to the story of destructors which are called in exactly the reverse order of the constructors – this is important because of potential dependencies.