读书人

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

发布时间: 2012-09-14 11:53:44 作者: rapoo

类模板和友元编译出错,求大神帮忙
#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也是免费的。

读书人网 >C++

热点推荐