类模板
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
主要是给自己看的,所以肯定会出现很多错误哈哈哈哈哈