我已经定义了这样的==操作符重载考虑非静态成员函数
using namespace std;
class foo {
public:
typedef std::pair< int, int > index;
bool operator == (const index &l, const index &r)
{
return (l.first == r.first && l.second == r.second);
}
void bar()
{
index i1;
i1.first = 10;
i1.second = 20;
index i2;
i2.first = 10;
i2.second = 200;
if (i1 == i2)
cout << "equal\n";
}
};
类不过,我得到的窗口
error C2804: binary 'operator ==' has too many parameters
这个错误,这个错误在linux
operator==(const std::pair<int, int>&, const std::pair<int, int>&)’ must take exactly one argument
我发现这个话题overloading operator== complaining of 'must take exactly one argument'和似乎是静态和非静态功能的问题 一类。但是我不知道如何申请this
例如,这是不正确的
bool operator == (const index &r)
{
return (this->first == r.first && this->second == r.second);
}
我该如何解决呢?
已经std :: pair没有得到一个==操作符? –