Sams Teach Yourself C++ in 21 Days

(singke) #1

470 Day 14


26: {
27: public:
28: Horse(COLOR color, HANDS height, int age);
29: virtual ~Horse() { cout << “Horse destructor...\n”; }
30: virtual void Whinny()const { cout << “Whinny!... “; }
31: virtual HANDS GetHeight() const { return itsHeight; }
32: virtual COLOR GetColor() const { return itsColor; }
33: protected:
34: HANDS itsHeight;
35: COLOR itsColor;
36: };
37:
38: Horse::Horse(COLOR color, HANDS height, int age):
39: Animal(age),
40: itsColor(color),itsHeight(height)
41: {
42: cout << “Horse constructor...\n”;
43: }
44:
45: class Bird : virtual public Animal
46: {
47: public:
48: Bird(COLOR color, bool migrates, int age);
49: virtual ~Bird() {cout << “Bird destructor...\n”; }
50: virtual void Chirp()const { cout << “Chirp... “; }
51: virtual void Fly()const
52: { cout << “I can fly! I can fly! I can fly! “; }
53: virtual COLOR GetColor()const { return itsColor; }
54: virtual bool GetMigration() const { return itsMigration; }
55: protected:
56: COLOR itsColor;
57: bool itsMigration;
58: };
59:
60: Bird::Bird(COLOR color, bool migrates, int age):
61: Animal(age),
62: itsColor(color), itsMigration(migrates)
63: {
64: cout << “Bird constructor...\n”;
65: }
66:
67: class Pegasus : public Horse, public Bird
68: {
69: public:
70: void Chirp()const { Whinny(); }
71: Pegasus(COLOR, HANDS, bool, long, int);
72: virtual ~Pegasus() {cout << “Pegasus destructor...\n”;}
73: virtual long GetNumberBelievers() const
74: { return itsNumberBelievers; }

LISTING14.6 continued
Free download pdf