< previous page page_255 next page >

Page 255
LISTING 16.3 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
28:
29:   class Dog : public Mammal
30:   {
31:   public:
32:
33:      // Constructors
34:      Dog();
35:      ~Dog();
36:
37:      // Accessors
38:      BREED GetBreed() const { return itsBreed; }
39:      void SetBreed(BREED breed) { itsBreed = breed; }
40:
41:      // Other methods
42:      void WagTail()const { cout << Tail wagging\n; }
43:      void BegForFood()const { cout << Begging for food\n; }
44:
45:   private:
46:      BREED itsBreed;
47:   };
48:
49:   Mammal::Mammal():
50:   itsAge(1),
51:   itsWeight(5)
52:   {
53:      cout << Mammal constructor\n;
54:   }
55:
56:   Mammal::~Mammal()
57:   {
58:      cout << Mammal destructor\n;
59:   }
60:
61:   Dog::Dog():
62:   itsBreed(YORKIE)
63:   {
64:      cout << Dog constructor\n;
65:   }
66:
67:   Dog::~Dog()
68:   {
69:      cout << Dog destructor\n;
70:   }
71:   int main()
72:   {
73:      Dog fido;
74:      fido.Speak();
75:      fido.WagTail();
76:      cout << Fido is  << fido.GetAge() <<  years old\n;
77:      return 0;
78:   }

 
< previous page page_255 next page >

If you like this book, buy it!