Whether there can be a situation where the syntax
if (first == second) // ...
is different from that?
if (first.operator==(second)) // ...
I don't think so, but just want to know it.
a == b
is sometimes equivalent to
a.operator==(b)
and sometimes equivalent to
operator==(a,b)
and sometimes equivalent to neither, if the meaning ends up being the "built-in" meaning of ==
for non-class types.
Whenever the compiler sees ==
, if at least one type involves a user-defined type, it searches for member operators (must not be hidden in the scope of a
's class type) and non-member operators (using argument dependent lookup) and built-in meanings (since a class might have an implicit conversion to an ordinary type with built-in comparison). If more than one could make sense, it goes to the rules for overload resolution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With