|
|
 |
|
|
|
|
44: else
45: pMammal = new Cat;
46:
47: Zoo[i] = pMammal;
48: }
49:
50: cout << \n;
51:
52: for (i=0; i<NumberMammals; i++)
53: {
54: Zoo[i] ->Speak();
55:
56: Cat *pRealCat = 0;
57: pRealCat = dynamic_cast< Cat *> (Zoo[i]);
58:
59: if (pRealCat)
60: pRealCat->Purr();
61: else
62: cout << Uh oh, not a cat!\n;
63:
64: delete Zoo[i];
65: cout << \n;
66: }
67:
68: return 0;
69: } |
|
|
|
|
|
|
|
|
(1)Dog (2)Cat: 1
Mammal constructor
Dog constructor
(1)Dog (2)Cat: 2
Mammal constructor
Cat constructor
(1)Dog (2)Cat: 1
Mammal constructor
Dog constructor
Woof!
Uh oh, not a cat!
Mammal destructor
Meow
rrrrrrrrrrr
Mammal destructor
Woof!
Uh oh, not a cat!
Mammal destructor |
|
|
|
|
|