|
|
|
|
|
|
|
The signature of a function is its name, as well as the number and type of its parameters. The signature does not include the return type. |
|
|
|
|
|
|
|
|
Listing 16.5 illustrates what happens if the Dog class overrides the speak() method in Mammal. To save room, the accessor functions have been left out of these classes. |
|
|
|
|
|
|
|
|
LISTING 16.5 OVERRIDING A BASE CLASS METHOD IN A DERIVED CLASS |
|
|
|
 |
|
|
|
|
1: //Listing 16.5 Overriding a base class method in a derived class
2:
3: #include <iostream.h>
4: enum BREED { YORKIE, CAIRN, DANDIE, SHETLAND, DOBERMAN, LAB };
5:
6: class Mammal
7: {
8: public:
9: // constructors
10: Mammal() { cout << Mammal constructor\n; }
11: ~Mammal() { cout << Mammal destructor\n; }
12:
13: //Other methods
14: void Speak()const { cout << Mammal sound!\n; }
15: void Sleep()const { cout << shhh. I'm sleeping.\n; }
16:
17:
18: protected:
19: int itsAge;
20: int itsWeight;
21: };
22:
23: class Dog : public Mammal
24: {
25: public:
26:
27: // Constructors
28: Dog(){ cout << Dog constructor\n; }
29: ~Dog(){ cout << Dog destructor\n; }
30:
31: // Other methods
32: void WagTail()const { cout << Tail wagging\n; }
33: void BegForFood()const { cout << Begging for food\n; }
34: void Speak()const { cout << Woof!\n; }
35:
36: private:
37: BREED itsBreed;
38: };
39:
40: int main() |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|