You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structA {
operatorint();
};
A operator+(const A&, const A&);
voidm() {
A a, b;
a + b; // operator+(a, b) chosen over int(a) + int(b)
}
Note the comment in this code, it sounds like the best overload is built-in operator. However, For this example, the candidate functions are a non-member user-defined function for operator + and a built-in operator, according to [over.match.best], convert these operands of type A to what the type build-in + expects, there are user-defined conversion sequences applied to these original operands, conversely, for user-declared operator +, only identity conversion applied to these operands, which is standard conversion sequences. Obviously, the later is more better. why the comment said chosen over int(a) + int(b)? GCC and Clang all agree that A operator+(const A&, const A&) is the best overload, Is it a typo?
The text was updated successfully, but these errors were encountered:
I disagree that the comment claims that the best operator is the built-in operator.
It clearly says you choose the (user-defined) operator+ in preference over the built-in operator.
"choose X over Y" means "take X because it's better / you like it more than Y".
Consider the example in over.match.oper#7, that is:
Note the comment in this code, it sounds like the best overload is built-in operator. However, For this example, the candidate functions are a non-member user-defined function for operator
+
and a built-in operator, according to [over.match.best], convert these operands of typeA
to what the type build-in+
expects, there are user-defined conversion sequences applied to these original operands, conversely, for user-declared operator+
, only identity conversion applied to these operands, which is standard conversion sequences. Obviously, the later is more better. why the comment saidchosen over int(a) + int(b)
? GCC and Clang all agree thatA operator+(const A&, const A&)
is the best overload, Is it a typo?The text was updated successfully, but these errors were encountered: