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

种模板和友元编译出错,求大神帮忙

2012-09-14 
类模板和友元编译出错,求大神帮忙#include iostreamusing std::coutusing std::endltemplate typenam

类模板和友元编译出错,求大神帮忙
#include <iostream>
using std::cout;
using std::endl;

template <typename T>
class ManyFriend
{
private:
T item;
public:
ManyFriend(const T & i):item(i){}
template<class C,class D>friend void show(const C &,const D &);
};

template <typename C,typename D>
void show(const C & c,const D & d)
{
cout<<c.item<<", "<<d.item<<endl;
}

int main()
{
ManyFriend<int> hfi1(10);
ManyFriend<int> hfi2(20);
ManyFriend<double> hfdb(10.5);

cout<<"hfi1, hfi2: ";
show(hfi1,hfi2);
cout<<"hfdb, hfi2: ";
show(hfdb,hfi2);

return 0;
}

编译器出错: error C2667: 'show' : none of 2 overload have a best conversion
  error C2668: 'show' : ambiguous call to overloaded function
        error C2667: 'show' : none of 2 overload have a best conversion
        error C2668: 'show' : ambiguous call to overloaded function

       帮我看下哪里出错了,谢谢大家!

[解决办法]
什么编译器?VC6的话就不要来折腾了,珍惜生命,远离VC6.
[解决办法]
gcc是免费的,VC20XX express也是免费的。

热点排行