STL之template类模板

 1 #include <iostream>
 2 using namespace std;
 3 
 4 template<class T>//类模板
 5 class Person{
 6     public://构造函数
 7         Person(T id,T age){
 8             this->mAge=age;
 9             this->mId=id;
10         }
11     void Show(){
12         cout<<"ID:"<<mId<<" Age:"<<mAge<<endl;
13     }
14     public:
15         T mId;
16         T mAge;
17 };
18 void test01(){
19     Person<int> p(10,20);
20     p.Show();
21 }
22 int main(){
23     test01();
24     return 0;
25 }

猜你喜欢

转载自www.cnblogs.com/Bravewtz/p/10325809.html