Sams Teach Yourself C++ in 21 Days

(singke) #1
Implementing Inheritance 383

12


81: Dog::Dog(int age):
82: Mammal(age),
83: itsBreed(GOLDEN)
84: {
85: cout << “Dog(int) constructor...” << endl;
86: }
87:
88: Dog::Dog(int age, int weight):
89: Mammal(age),
90: itsBreed(GOLDEN)
91: {
92: itsWeight = weight;
93: cout << “Dog(int, int) constructor...” << endl;
94: }
95:
96: Dog::Dog(int age, int weight, BREED breed):
97: Mammal(age),
98: itsBreed(breed)
99: {
100: itsWeight = weight;
101: cout << “Dog(int, int, BREED) constructor...” << endl;
102: }
103:
104: Dog::Dog(int age, BREED breed):
105: Mammal(age),
106: itsBreed(breed)
107: {
108: cout << “Dog(int, BREED) constructor...” << endl;
109: }
110:
111: Dog::~Dog()
112: {
113: cout << “Dog destructor...” << endl;
114: }
115: int main()
116: {
117: Dog Fido;
118: Dog rover(5);
119: Dog buster(6,8);
120: Dog yorkie (3,GOLDEN);
121: Dog dobbie (4,20,DOBERMAN);
122: Fido.Speak();
123: rover.WagTail();
124: cout << “Yorkie is “ << yorkie.GetAge()
125: << “ years old” << endl;
126: cout << “Dobbie weighs “;
127: cout << dobbie.GetWeight() << “ pounds” << endl;
128: return 0;
129: }

LISTING12.4 continued

Free download pdf