I was looking at the C++ standard regarding member reference operators (the unary *
dereferencing operator, the ->
member accessor operator) as well as many other related questions:
C++ - Difference between (*). and ->?
ptr->hello(); /* VERSUS */ (*ptr).hello();
C++ pointers difference between * and ->
I saw that most answers stated that p->m
is syntactic sugar for (*p).m
as defined by the C++ Standard (5.2.5, paragraph 2):
The expression
E1->E2
is converted to the equivalent form(*(E1)).E2
Many comments also noted that because operator*
and operator->
are overloadable in classes, they should be overloaded uniformly to ensure consistent behavior.
These statements seem to contradict each other: if (as per the standard) E1->E2
is converted to the equivalent form (*(E1)).E2
, then what would be the purpose of overloading operator->
(as is permitted by the standard)?
Simpler stated, are these two parts of the standard in conflict, or am I misunderstanding the Standard?
Does the E1->E2
equivalence transformation to (*(E1)).E2
apply to all complete types or only to built in ones?