我试图重载operator==
,但编译器抛出以下错误:
‘bool Rationalnumber::operator==(Rationalnumber, Rationalnumber)’ must take exactly one argument
我的一小段代码如下:
bool Rationalnumber::operator==(Rationalnumber l, Rationalnumber r) {
return l.numerator() * r.denominator() == l.denominator() * r.numerator();
}
宣言:
bool operator==( Rationalnumber l, Rationalnumber r );
有谁知道为什么会抛出错误?