int main() { Mammal *pDog = new Dog; pDog->move(); pDog->speak(); return 0; }
int main() { Mammal *pDog = new Dog; pDog->move(); // pDog is a Mammal pointer. The mammal method gets called. pDog->speak(); // ... but the Mammal.speak() method is virtual, so the Dog.speak() method is used instead. return 0; }
int main() { Mammal *pDog = new Dog; pDog->move(); pDog->speak(); //pDog->tail(); cout << "--------------\n"; Mammal *super = new Dog; super->speak(); super->move(); cin.get(); return 0; }
int main() { Mammal *pCat = new Cat; pCat->speak(); return 0; }