示例#1
0
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;
}
示例#2
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;
}
示例#3
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;
}