- #include
-
- 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
a("dog","wang") ; - Action
b("cat","miao") ; - Action
c("cow","mou") ; - a.perform();
- b.perform();
- c.perform();
- return 0;
- }