- #include
-
- using namespace std;
-
- class Animal
- {
- private:
- string introduce;
- public:
- Animal(){}
- Animal(string i):introduce(i)
- {}
- virtual void perform() = 0;
- };
-
- class Lion:public Animal
- {
- private:
- int age;
- public:
- Lion(){}
- Lion(string i,int a):Animal(i),age(a)
- {}
- void perform()
- {
- cout << "狮子在空中旋转了360度然后完美落地" << endl;
- }
- };
-
- class Monkey:public Animal
- {
- private:
- string name;
- public:
- Monkey(){}
- Monkey(string i,string n):Animal(i),name(n)
- {}
- void perform()
- {
- cout << "猴子从耳中掏出了一根棍子,并大喊一声吾乃齐天大圣" << endl;
- }
- };
-
- int main()
- {
- Lion l("动物园二傻子",2);
- Monkey m("动物园扛把子","美猴王");
- Animal *p;
- p = &l;
- p->perform();
- p = &m;
- p->perform();
- return 0;
- }