作业:
#include <iostream>
using namespace std;
class Animal
{
public:
Animal() {}
virtual void perform()=0;
};
class Lion:public Animal
{
public:
void perform()
{
cout << "lion can loud-bark!" << endl;
}
};
class Elephant:public Animal
{
public:
void perform()
{
cout << "elephant can play ball!" << endl;
}
};
class Monkey:public Animal
{
public:
void perform()
{
cout << "monkey can ride bike!" << endl;
}
};
void introducer(Animal &animal)
{
animal.perform();
}
int main()
{
Lion lion;
Elephant elephant;
Monkey monkey;
introducer(lion);
introducer(elephant);
introducer(monkey);
return 0;
}
运行结果