出拳小游戏
#include<iostream>using namespace std;
class poser
{
public:
virtual void beat()const{cout<<"输出一般选手的力量为260磅\n";}
protected:
int age;
};
class Ali:public poser
{
public:
void beat()const{cout<<"阿里一拳的力量为420磅\n";}
};
class Lewis:public poser
{
public:
void beat()const{cout<<"刘易斯一拳的力量为480磅\n";}
};
class Tyson:public poser
{
public:
void beat()const{cout<<"泰森一拳的力量为500磅\n";}
};
class Holy:public poser
{
public:
void beat()const{cout<<"霍利非瓦尔德一拳的力量为350磅\n";}
};
int main()
{
poser *p[5];
poser *p1;
int choice,i;
for(i=0;i<5;i++)
{
cout<<"(1)阿里(2)刘易斯(3)泰森(4)霍利菲尔德:";}
cin>>choice;
switch(choice)
{
case 1:p=new Ali;
break;
case 2:p=new Lewis;
break;
case 3:p=new Tyson;
break;
case 4:p=new Holy;
break;
default:p=new poser;
break;
}
p[i]=p1;
p[i]->beat();
}
return 0;
}
这段代码出错,出在哪????