In this video, we'll see a simple example of
multiple inheritance in c++.
Multiple inheritance occurs when a derived class inherits from two or
more base classes at the same time.
The base classes may belong to unrelated class hierarchies.
The class diagram on the right shows an example of multiple inheritance.
In this case, the class department chair is derived from both
faculty and administrator classes.
So if we use public inheritance, then a department chair is a
faculty member and a department chair is also an administrator.
The c++ syntax for multiple inheritance is simple.
We declare our derived class and then provide a comma separated list of the
base classes that it's derived from.
In this case, department chair is our derived class, and its base
classes are faculty and administrator.
We're only showing public inheritance here, but we could also use the
other types of c++ inheritance.
Multiple inheritance is beyond the scope of this course, and it can
be very, very complex in practice.
There are some compelling use cases for multiple inheritance.
However, in many cases we can refactor our design so that the multiple
inheritance can be avoided, and many times we end up with a better design.
This isn't because there's anything wrong with multiple inheritance.
The problem with multiple inheritance is that because it can be so complex,
many developers don't fully understand it, and, therefore, may misuse it.
More often, you see multiple inheritance in class libraries and
frameworks that you might be using.