且生 发表于 2013-2-26 14:01

求助:类模版==的操作符重载,请大家教教我这代码错哪了

#include<iostream>
using namespace std;
template<class T>
class Sample
{
private:
        T n;
public:
        Sample():n(0){}
        Sample(T a):n(a){}
        friend bool operator== (const Sample<T>&,const Sample<T>&);
};

int main()
{
        Sample<int> a(10),b(2);
        if(a==b)cout<<"true";
        else cout<<"false";
        cout<<endl;
        system("pause");
        return 0;
}
template<class T>
bool operator==(const Sample<T>& a,const Sample<T>& b)
{
        if(a.n==b.n)
                return true;
        else return false;
}==用来比较两个数。

wangzheng3056 发表于 2013-7-22 11:49

楼主解决了吗?  跪求科普~!
页: [1]
查看完整版本: 求助:类模版==的操作符重载,请大家教教我这代码错哪了