且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

点 (.) 运算符和 -> 有什么区别?在 C++ 中?

更新时间:2023-11-12 17:39:10

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++?