1. 程式人生 > >STL之template類模板

STL之template類模板

std cout mes 模板 span clas str div public

 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 }

STL之template類模板