...

/

Inheriting from Multiple Classes

Inheriting from Multiple Classes

Learn how a class can inherit from multiple classes using multilevel inheritance.

Up until now, we have understood how a (child) class can inherit from another (parent) class. But in C++, it’s also possible that a class can inherit from more than one base class. This can be done using different methods. Let’s explore some of these methods and the potential issues that can arise with this.

Multilevel inheritance

To understand multilevel inheritance, imagine a family tree. In a family tree, there can be grandparents, parents, and children. In programming, this is similar to multilevel inheritance.

Multilevel inheritance occurs when a class is derived from another derived class. This means that a class (child class) inherits from a base (parent) class, and this base (parent) class also inherits from another base (grandparent) class. This can be illustrated as:

Press + to interact
Multilevel inheritance
Multilevel inheritance

...