Polymorphism 457
14
LISTING14.3 Multiple Inheritance
0: // Listing 14.3. Multiple inheritance.
1:
2: #include <iostream>
3: using std::cout;
4: using std::cin;
5: using std::endl;
6:
7: class Horse
8: {
9: public:
10: Horse() { cout << “Horse constructor... “; }
11: virtual ~Horse() { cout << “Horse destructor... “; }
12: virtual void Whinny() const { cout << “Whinny!... “; }
13: private:
14: int itsAge;
15: };
16:
17: class Bird
18: {
19: public:
20: Bird() { cout << “Bird constructor... “; }
21: virtual ~Bird() { cout << “Bird destructor... “; }
22: virtual void Chirp() const { cout << “Chirp... “; }
23: virtual void Fly() const
24: {
25: cout << “I can fly! I can fly! I can fly! “;
26: }
27: private:
28: int itsWeight;
29: };
30:
31: class Pegasus : public Horse, public Bird
32: {
33: public:
34: void Chirp() const { Whinny(); }
35: Pegasus() { cout << “Pegasus constructor... “; }
36: ~Pegasus() { cout << “Pegasus destructor... “; }
37: };
38:
39: const int MagicNumber = 2;
40: int main()
41: {
42: Horse* Ranch[MagicNumber];
43: Bird* Aviary[MagicNumber];
44: Horse * pHorse;
45: Bird * pBird;
46: int choice,i;
47: for (i=0; i<MagicNumber; i++)