Multiple Inheritance will cause one grandson has two copy of grandfathers.
A solution is use virtual key word: When you use this method, you need to
follow New Constructor Rules, Detail can be seen in C++ primer P815. Just
look back when you really need MI.
A design discussion can be seen in "C++ FAQ Inheritance– Multiple and
Virtual Inheritance"
Suppose you have land vehicles, water vehicles, air vehicles, and space
vehicles. (Forget the whole concept of amphibious vehicles for this
example; pretend they don’t exist for this illustration.) Suppose we also
have different power sources: gas powered, wind powered, nuclear
powered, pedal powered, etc. We could use multiple inheritance to tie
everything together, but before we do, we should ask a few tough
questions:
Will the users of LandVehicle need to have a Vehicle& that refers
to a LandVehicle object? In particular, will the users call methods
on a Vehicle-reference and expect the actual implementation of
those methods to be specific to LandVehicles?
Ditto for GasPoweredVehicles: will the users want a Vehicle
reference that refers to a GasPoweredVehicle object, and in
particular will they want to call methods on that Vehicle
reference and expect the implementations to get overridden by
GasPoweredVehicle?
If both answers are "yes," multiple inheritance is probably the best way to
go.
There are at least three choices for the overall design: the bridge
pattern, nested generalization, and multiple inheritance. Each has its
pros/cons:
Try especially hard to use ABCs when you use MI. In particular, most
classes above the join class (and often the join class itself) should be ABCs.
In this context, "ABC" doesnâĂŹt simply mean "a class with at least one
pure virtual function;" it actually means a pure ABC, meaning a class with
as little data as possible (often none), and with most (often all) its methods
being pure virtual.
Where in a hierarchy should I use virtual inheritance? Just below the top of
the diamond, not at the join-class.