|
|
 |
|
|
|
|
18: public:
19: void Speak()const { cout << Woof!\n; }
20: void Move() const { cout << Walking to heel\n; }
21: };
22:
23:
24: class Cat : public Mammal
25: {
26: public:
27: void Speak()const { cout << Meow!\n; }
28: void Move() const { cout << slinking\n; }
29: };
30:
31:
32: class Horse : public Mammal
33: {
34: public:
35: void Speak()const { cout << Winnie!\n; }
36: void Move() const { cout << Galloping\n; }
37: };
38:
39:
40: int main()
41: {
42: void (Mammal::*pFunc)() const =0;
43: Mammal* ptr =0;
44: int Animal;
45: int Method;
46: bool fQuit = false;
47:
48: while (fQuit == false)
49: {
50: cout << (0)Quit (1)dog (2)cat (3)horse: ;
51: cin >> Animal;
52: switch (Animal)
53: {
54: case 1: ptr = new Dog; break;
55: case 2: ptr = new Cat; break;
56: case 3: ptr = new Horse; break;
57: default: fQuit = true; break;
58: }
59: if (fQuit)
60: break;
61:
62: cout << (1)Speak (2)Move: ;
63: cin >> Method;
64: switch (Method)
65: {
66: case 1: pFunc = Mammal::Speak; break; |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|