460 Day 14
The Parts of a Multiply Inherited Object ......................................................
When thePegasusobject is created in memory, both the base classes form part of the
Pegasusobject, as illustrated in Figure 14.1. This figure represents an entire Pegasus
object. This includes the new features added in the Pegasusclass and the features picked
up from the base classes.
FIGURE14.1
Multiply inherited
objects. Horse
Bird
Pegasus
Several issues arise with objects with multiple base classes. For example, what happens
if two base classes that happen to have the same name have virtual functions or data?
How are multiple base class constructors initialized? What happens if multiple base
classes both derive from the same class? The next sections answer these questions and
explore how multiple inheritance can be put to work.
Constructors in Multiply Inherited Objects....................................................
If Pegasusderives from both Horseand Bird, and each of the base classes has construc-
tors that take parameters, the Pegasusclass initializes these constructors in turn. Listing
14.4 illustrates how this is done.
LISTING14.4 Calling Multiple Constructors
0: // Listing 14.4
1: // Calling multiple constructors
2:
3: #include <iostream>
4: using namespace std;
5:
6: typedef int HANDS;
7: enum COLOR { Red, Green, Blue, Yellow, White, Black, Brown } ;
8:
9: class Horse
10: {
11: public: