The member access operator .*
has a higher precedence than the negation operator !
.
Where this behaviour is described in C++ standard, or maybe is this some kind of undefined behaviour?
This is most likely the relevant paragraph:
13.5 Overloaded operators [over.oper]
5) Operator functions are usually not called directly; instead they are invoked to evaluate the operators they implement (13.5.1 – 13.5.7). They can be explicitly called, however, using the operator-function-id as the name of the function in the function call syntax (5.2.2).
In your first example t > 0;
it will use the according operator with the precedence for the relational comparison operators. However, in your second version t.operator>(0)
you use it as a function call. Thereby the Test::operator>
is used as a member function, which will result in your described behavior, as it looses its operator characteristics ("they can be explicitly called, however, using the operator-function-id as the name of the function in the function call syntax").
See also: