- #include
-
- using namespace std;
- class Animal
- {
- public:
- virtual void perform()=0;
- };
- template <class Y,class L>
- class Action : public Animal
- {
- Y a;
- L b;
- public:
- Action(){}
- Action(Y a,L b):a(a),b(b){}
- void perform()
- {
- cout << a << "正在" << b <
- }
- };
- int main()
- {
- Animal *p1,*p2,*p3;
- Action
s1("猴子","唱歌"); - p1 = &s1;
- p1 -> perform();
- Action
s2("老虎","咆哮"); - p2 = &s2;
- p2 -> perform();
- Action
s3("熊猫","吃竹子"); - p3 = &s3;
- p3 ->perform();
- return 0;
- }
