cpp
复制代码
#include <iostream>
using namespace std;
class Animal
{
private:
string name;
public:
Animal() {}
Animal(string name):name(name){}
virtual void perform()=0;
void show()
{
cout << name << ":" ;
}
};
template <typename T>
class Action:Animal
{
private:
T action;
public:
Action() {}
Action(string name,T action):Animal(name),action(action)
{}
void perform()
{
Animal::show();
cout << action << endl;
}
};
int main()
{
Action<string> a("dog","wang");
Action<string> b("cat","miao");
Action<string> c("cow","mou");
a.perform();
b.perform();
c.perform();
return 0;
}