What is the difference between the dot (.) operator and -> in C++? [duplicate]

foo->bar() is the same as (*foo).bar().

The parenthesizes above are necessary because of the binding strength of the * and . operators.

*foo.bar() wouldn’t work because Dot (.) operator is evaluated first (see operator precedence)

The Dot (.) operator can’t be overloaded, arrow (->) operator can be overloaded.

The Dot (.) operator can’t be applied to pointers.

Also see: What is the arrow operator (->) synonym for in C++?

Leave a Comment