类模板

 1 //
 2 // Created by Administrator on 2021/7/15.
 3 //
 4 
 5 #ifndef C__TEST01_PERSON_H
 6 #define C__TEST01_PERSON_H
 7 
 8 //类模板
 9 template<class T1, class T2>
10 class person{
11 public:
12     person(T1 name, T2 age);
13     void printAge();
14 private:
15     T1 name;
16     T2 age = 100;
17 };
18 
19 template<class T1, class T2>
20 person<T1,T2>::person(T1 name,T2 age) :
21 name(name),age(age)
22 {}
23 
24 template<class T1, class T2>
25 void person<T1,T2>:: printAge(){
26     cout<<"age:"<<this->age<<endl;
27 }
28 
29 #endif //C__TEST01_PERSON_H

 

posted @ 2021-07-15 19:56  蘑菇王国大聪明  阅读(28)  评论(0编辑  收藏  举报