1.
2
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void perform()
{}
};
class Monkey:public Animal
{
private:
string name;
public:
Monkey(){}
Monkey(string n):name(n){}
void perform()
{
cout << name << " " << "正在翻跟斗" << endl;
}
};
class Lion:public Animal
{
private:
string name;
public:
Lion(){}
Lion(string n):name(n){}
void perform()
{
cout << name << " " << "正在钻火圈" << endl;
}
};
int main()
{
Monkey a("王震宇");
Lion b("王震宇");
Animal *p;
p=&a;
p->perform();
p=&b;
p->perform();
return 0;
}