Multiple inheritance is a type of inheritance where a class inherits from two or more base classes. It allows a derived class to combine the properties and behaviors of multiple parent classes into a single class.
- Enables a class to reuse functionality from multiple base classes.
- Helps combine related features without duplicating code.
Example:
- A CHILD class is derived from the FATHER and MOTHER class
- A PETROL class is derived from the LIQUID and FUEL class.

Example: The following example demonstrates how a class can inherit from multiple base classes:
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Class A\n";
}
};
class B
{
public:
B()
{
cout << "Class B\n";
}
};
// Inheriting from both class A & B
class C : public B, public A
{
public:
C()
{
cout << "Class C\n";
}
};
int main()
{
C obj;
}
Output
Class B Class A Class C
Explanation: In the above code, class C inherits from both B and A using multiple inheritance (class C : public B, public A).
Syntax
A derived class inherits from multiple base classes by specifying all parent classes after the inheritance operator (:).
class Base1 {
// Members of Base1
};class Base2 {
// Members of Base2
};class Derived : public Base1, public Base2 {
// Members of Derived
};
Where:
- Base1 and Base2 are the parent classes.
- Derived inherits the accessible members of both base classes.
- Multiple base classes are separated using commas.
Constructor Call Order
In Constructor Call Order When an object of a multiply inherited class is created, the constructors of the base classes are executed before the derived class constructor.
- Base class constructors are called first.
- The order depends on the inheritance list.
- The constructor body does not affect this order.
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Constructor A\n";
}
};
class B
{
public:
B()
{
cout << "Constructor B\n";
}
};
class C : public B, public A
{
public:
C()
{
cout << "Constructor C\n";
}
};
int main()
{
C obj;
}
Output
Constructor B Constructor A Constructor C
Explanation: Although A is defined before B, C inherits as public B, public A. Therefore:
- B constructor executes first.
- A constructor executes next.
- C constructor executes last.
Destructor Call Order
Destructors execute in the reverse order of constructors.
- The derived class destructor executes first.
- Base class destructors execute afterward.
- Base classes are destroyed in reverse inheritance order.
#include <iostream>
using namespace std;
class A
{
public:
~A()
{
cout << "Destructor A\n";
}
};
class B
{
public:
~B()
{
cout << "Destructor B\n";
}
};
class C : public B, public A
{
public:
~C()
{
cout << "Destructor C\n";
}
};
int main()
{
C obj;
}
Output
Destructor C Destructor A Destructor B
Explanation: Objects are destroyed in the reverse order of construction. The destructor sequence is: C A B
Diamond Problem
The Diamond Problem occurs when two classes inherit from the same base class, and a third class inherits from both of them. This leads to duplication of base class members and causes ambiguity.

In this example, we demonstrate the diamond problem where the base class constructor is called twice due to multiple inheritance.
#include <iostream>
using namespace std;
class Person
{
public:
Person()
{
cout << "Person constructor\n";
}
};
class Faculty : public Person
{
};
class Student : public Person
{
};
class TA : public Faculty, public Student
{
};
int main()
{
TA obj;
}
Output
Person constructor Person constructor
Explanation: TA inherits from both Faculty and Student, and both inherit from Person. As a result:
- Two separate Person objects are created.
- The Person constructor executes twice.
- This leads to ambiguity because TA contains two copies of the Person class.
Advantages of Multiple Inheritance
Multiple inheritance allows a class to combine functionality from different base classes.
- Reuses functionality from multiple classes.
- Reduces code duplication.
- Combines independent features into a single class.
- Improves flexibility in class design.
Limitations of Multiple Inheritance
Although powerful, multiple inheritance increases program complexity.
- May introduce ambiguity when members have the same name.
- Can lead to the Diamond Problem.
- Makes class hierarchies more difficult to understand and maintain.
- Requires virtual inheritance to resolve shared base class issues.