首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

pair种中的模板构造函数

2012-09-09 
pair类中的模板构造函数在pair类里的模板构造函数template class T1,class T2{..template class u,clas

pair类中的模板构造函数
在pair类里的模板构造函数
template <class T1,class T2>
{
..
  template <class u,class v>
  pair(const pair<u,v> &p):first(p.first),second(p.second){}
...
}
书上说是因为构造过程中可能需要隐式转换,调用有系统生成的copy构造函数,
void f(std::pair<int,const char*>)
void g(std::pair<const int,std::string>)

void foo()
{
std::pair<int,const char*> p(42,"hello");
f(p);
g(p);
}
但是我用
pair(const pair<T1,T2>& p):first(p.first),second(p.second){}也能实现啊,为什么非得用成员模板函数呢

[解决办法]

C/C++ code
参考:http://dev.yesky.com/441/2256441.shtml 

热点排行