Polymorphism 461
14
12: Horse(COLOR color, HANDS height);
13: virtual ~Horse() { cout << “Horse destructor...\n”; }
14: virtual void Whinny()const { cout << “Whinny!... “; }
15: virtual HANDS GetHeight() const { return itsHeight; }
16: virtual COLOR GetColor() const { return itsColor; }
17: private:
18: HANDS itsHeight;
19: COLOR itsColor;
20: };
21:
22: Horse::Horse(COLOR color, HANDS height):
23: itsColor(color),itsHeight(height)
24: {
25: cout << “Horse constructor...\n”;
26: }
27:
28: class Bird
29: {
30: public:
31: Bird(COLOR color, bool migrates);
32: virtual ~Bird() {cout << “Bird destructor...\n”; }
33: virtual void Chirp()const { cout << “Chirp... “; }
34: virtual void Fly()const
35: {
36: cout << “I can fly! I can fly! I can fly! “;
37: }
38: virtual COLOR GetColor()const { return itsColor; }
39: virtual bool GetMigration() const { return itsMigration; }
40:
41: private:
42: COLOR itsColor;
43: bool itsMigration;
44: };
45:
46: Bird::Bird(COLOR color, bool migrates):
47: itsColor(color), itsMigration(migrates)
48: {
49: cout << “Bird constructor...\n”;
50: }
51:
52: class Pegasus : public Horse, public Bird
53: {
54: public:
55: void Chirp()const { Whinny(); }
56: Pegasus(COLOR, HANDS, bool,long);
57: ~Pegasus() {cout << “Pegasus destructor...\n”;}
58: virtual long GetNumberBelievers() const
59: {
LISTING14.4 continued