To clarify from my comment, this will support the code so that you can either provide all the options for the operators:
inline bool operator==(const MyClass& lhs, const MyClass& rhs) { return lhs.middle == rhs.middle; } inline bool operator==(const int& lhs, const MyClass& rhs) { return lhs == rhs.middle; } inline bool operator==(const MyClass& lhs, const int& rhs) { return lhs.middle == rhs; }
And do it for each operator (which will explode on a significant amount of code). OR, if that makes sense, you can provide a constructor that builds from int:
struct MyClass { MyClass() {}
If you do this, you only need the version of MyClass, MyClass for each statement:
inline bool operator==(const MyClass& lhs, const MyClass& rhs) { return lhs.middle == rhs.middle; }
Because when the compiler sees:
if ( 5 == my_class ) {}
Actually it does:
if ( MyClass(5).operator==( my_class ) ) {}
qeadz source share