#include <iostream>
using namespace std;
class Animal
{
private:
string name;
public:
Animal() {}
Animal(string name):name(name)
{}
virtual void prefrom() = 0;
void show()
{
cout << name << ":";
}
};
template <class T>
class Anmimal_action:Animal
{
private:
T action;
public:
Anmimal_action() {}
Anmimal_action(T n,T a):Animal(n),action(a)
{}
void prefrom()
{
Animal::show();
cout << action << endl;
}
};
int main()
{
Anmimal_action<string> a1("狮子","狗叫");
Anmimal_action<string> a2("大象","摇耳朵");
Anmimal_action<string> a3("猴子","挠头");
a1.prefrom();
a2.prefrom();
a3.prefrom();
return 0;
}
10.12作业
最新推荐文章于 2024-11-14 19:11:37 发布