7: public:
8: void Move() const { cout << “Mammal move one step\n”; }
9: void Move(int distance) const
10: {
11: cout << “Mammal move “ << distance;
12: cout << “ steps.” << endl;
13: }
14:
15: protected:
16: int itsAge;
17: int itsWeight;
18: };
19:
20: class Dog : public Mammal
21: {
22: public:
23: void Move() const;
24: };
25:
26: void Dog::Move() const
27: {
28: cout << “In dog move...\n”;
29: Mammal::Move(3);
30: }
31:
32: int main()
33: {
34: Mammal bigAnimal;
35: Dog Fido;
36: bigAnimal.Move(2);
37: Fido.Mammal::Move(6);
38: return 0;
39: }
Mammal move 2 steps.
Mammal move 6 steps.
On line 34, a Mammal,bigAnimal, is created, and on line 35, a Dog,Fido, is cre-
ated. The method call on line 36 invokes the Move()method of Mammal, which
takes an integer.
The programmer wanted to invoke Move(int)on the Dogobject, but had a problem. Dog
overrides the Move()method (with no parameters), but does not overload the method that
takes an integer—it does not provide a version that takes an integer. This is solved by the
explicit call to the base class Move(int)method on line 37.
OUTPUT
390 Day 12
LISTING12.7 continued
ANALYSIS