79431138

Date: 2025-02-11 19:32:35
Score: 2
Natty:
Report link

Try the following minimal example:

struct Spot {
    int x, y;
};

int main() {
    Spot{0, 1} == Spot{2, 3};
}

This doesn't compile, as you can test for yourself.

<source>(56): error C2676: binary '==': 'Spot' does not define this operator or a conversion to a type acceptable to the predefined operator

In this case, the error message is way clearer. The compiler doesn't know, how to compare to objects of type Spot and how should it, you never defined how that would work.

You can help yourself with a defined operator==() like the following:

bool operator==(const Spot& lhs, const Spot& rhs) {
    return lhs.x == rhs.x && lhs.y == rhs.y;
}
Reasons:
  • Blacklisted phrase (1): how should i
  • Whitelisted phrase (-1): Try the following
  • RegEx Blacklisted phrase (3): You can help
  • Long answer (-0.5):
  • Has code block (-0.5):
Posted by: Joel