my_pair

eggache了一下.为了防止自己脑袋秀逗了,试了一下这个。大概这个意思,不过重载运算符没弄,用到字符串类型会有问题。

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

namespace Y4
{
template <typename T1, typename T2>
class pair
{
public:
T1 first;
T2 second;
pair() {;}
pair(T1 val1, T2 val2)
{
first = val1;
second = val2;
}
};
}

void main()
{
Y4::pair<int ,int> p;
p = Y4::pair<int, int>(1, 2);
//p = Y4::pair<int, string>(1, "qwerty");

cout<<"first:\t"<<p.first<<endl;
cout<<"second:\t"<<p.second<<endl;

system("pause");
}



posted on 2012-02-10 10:08  shizuka  阅读(188)  评论(0编辑  收藏  举报

导航