Why is this error message appearing?
If you implement the binary operator as a member function, it takes only the right side as an argument, and the left side is the caller. If you write:
a == b
the compiler is looking for a function that matches either:
(return type) (type of lhs)::operator==( (type of rhs));
or
(return type) operator==( (type of lhs), (type of rhs) );
: ( ) , bool . , .
:
(return type) (type: family)::operator==( (type: family), (type: family) );
( )!
, , "&" in (const family &, const family &).
const family & - , . family (.. , ), promises (const). . , , , . , .
- :
class family
{
bool operator==(
}
, . , :
bool operator==(const family&)
. , non-member "const family &" ? , const. , const :
bool operator==(const family&) const;
( .)
, :
bool family::operator==(const family &rhs) const {
...
}
rhs :
return weight == rhs.weight;
return getWeight() == rhs.getWeight(); // using functions