您的位置:首页 > 大数据 > 人工智能

<STL> pair随笔

2010-12-18 16:46 267 查看
C++标准中提供了pair<T1,T2>类型,今天想自己写一个,在实际动手过程中,自定义的类名不能是pair,否则会和C++标准中的pair类冲突,于是我定义成了pair1。这里我有点不太明白的是,我们都知道pair是在头文件utility.h中定义的,我并没有引入这个头文件,但居然编译的时候提示pair已经定义,不明白....

#include <iostream>
#include <string>
using namespace std;

template<class T1,class T2>
class pair1
{
public:
T1 first;
T2 second;
//pair1():first(T1()),second(T2()){}
pair1():first(),second(){}
pair1(const T1& t1,const T2& t2):first(t1),second(t2){}
};

int main()
{
pair1<int,int>p1;
pair1<string,int>p2("hicjiajia",425);
cout<<p1.first<<" "<<p1.second<<endl;
cout<<p2.first<<" "<<p2.second<<endl;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: