- #include
-
- using namespace std;
-
-
- class Animal
- {
- public:
- string name;
- int age;
- public:
- Animal() {}
- Animal(string n,int a):name(n),age(a){}
- virtual void perfrom()
- {
- }//虚函数
- virtual ~Animal(){}
- };
-
- template <typename N,typename T>
- class Start :public Animal
- {
- N voice;
- T strong;
- public:
- Start(){}
- Start(string n,int a,N v,T s):Animal(n,a),voice(v),strong(s){}
- ~Start(){}
- void perfrom()
- {
- cout << name << " 今年 " << age << "岁 " << "叫声是 "<< voice << endl;
- }
- void strong_point()
- {
- cout << "它会 " << strong << endl;
- }
-
- };
-
- int main()
- {
- Start
s1("哈士奇",2,"汪汪汪","啃沙发") ; - Start
s2("猫咪",3,"喵喵喵","半夜吵醒你") ; - Animal *a;//若是一个抽象类,则不能实例化
- a = &s1;
- a->perfrom();
- s1.strong_point();
- a = &s2;
- a->perfrom();
- s2.strong_point();
- return 0;
- }