码迷,mamicode.com
首页 > 其他好文 > 详细

STL之template类模板

时间:2019-01-27 12:57:17      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:main   stl   his   names   void   code   函数   test   temp   

 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类模板

标签:main   stl   his   names   void   code   函数   test   temp   

原文地址:https://www.cnblogs.com/Bravewtz/p/10325809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!