#include <iostream>using namespace std;class Animal//封装 动物 基类
{
private:string name;
public:Animal() {}Animal(string n):name(n){}virtual void perform() //虚函数{cout << "欢迎来到动物园" << endl;}
};class Lion:public Animal //封装 狮子 子类 共有继承于 动物 基类
{
private:int id;
public:Lion(){}Lion(string n,int i):Animal(n),id(i){}void speak(){cout << "狮子:吼!" << endl;}};class Monkey:public Animal //封装 猴子 子类 共有继承于 动物 基类
{
private:int id;
public:Monkey() {}Monkey(string n,int d):Animal(n),id(d){}void speak(){cout << "猴子:呜叽叽" << endl;}
};int main()
{Lion l("狮子",1);Monkey m("猴子",2);Animal *p;//基类的指针p = &l;p->perform();l.speak();p = &m;p->perform();m.speak();return 0;
}