int main(){ Animal myAnimal; Dog myDog; Animal *AnimalPtr; AnimalPtr = &myDog; myAnimal.whoAmI(); myAnimal.does(); myDog.whoAmI(); myDog.does(); cout << "Dogs have " << myDog.howManyLegs() << " legs" << endl; cout << "Using the base pointer to access derived class object" << endl; AnimalPtr->whoAmI(); AnimalPtr->does(); AnimalPtr = &myAnimal; AnimalPtr->does(); }
int main(){ //To demonstrate polymorphism I'll create a pointer of type Animal and use it to access the subclass animals Animal *p = new Bird(); p->name(); p->does(); Animal *t = new Dog(); t->name(); t->does(); delete p; delete t; //This demonstrates overriding of the pure virtual functions in the abstract class Animal system("PAUSE"); return 0; }
int main() { Animal *p = new Bird; Animal *p1 = new Dog; p->name(); p->does(); p1->name(); p1->does(); system("pause"); }