10_12C++

X-mind

10_12C++_第1张图片

#include 

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;
}

你可能感兴趣的:(c++,开发语言)