int main() { Animal *p = NULL; char t; cin >> t; if(t=='t') p = new Tiger; else p = new Horse; p->play(); delete p; return 0; }
int main() { Animal* p = NULL; char choice; cout <<"h---Horse, t--Tiger, please make a chioce:"; cin >> choice; if(choice=='h') p = new Horse; else p = new Tiger; p->play(); cout << "====================" << endl; p->Animal::eat();//p指向的是Animal 里面的eat()函数 cout << "====================" << endl; delete p; return 0; }
int main() { Animal* p = NULL; char choice; cout << "h--Âí, t--ÀÏ»¢, ÇëÑ¡Ôñ:"; cin >> choice; if(choice=='h') p = new Horse; else p = new Tiger; p->play(); cout << "=================" << endl; p->Animal::eat(); cout << "=================" << endl; delete p; return 0; }