我定义了一个类,就像这样
然而,我在Windows系统中遇到了这个错误。
在Linux中出现的这个错误。
我发现了这个主题“重载运算符== complaining of 'must take exactly one argument'”,似乎是与类中的静态和非静态函数有关的问题。然而我不知道如何应用
例如,以下内容是不正确的。
我该如何解决这个问题?
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";
}
};
然而,我在Windows系统中遇到了这个错误。
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
我发现了这个主题“重载运算符== complaining of 'must take exactly one argument'”,似乎是与类中的静态和非静态函数有关的问题。然而我不知道如何应用
this
。例如,以下内容是不正确的。
bool operator == ( const index &r )
{
return (this->first == r.first && this->second == r.second);
}
我该如何解决这个问题?