C++ pointers difference between * and -> [duplicate]

半世苍凉 提交于 2019-12-04 06:44:13

问题


Possible Duplicate:
C++: ptr->hello(); /* VERSUS */ (*ptr).hello();

Too bad I can't google this...

Could someone explain or point me to where I can find the difference between these two? I understand * is a dereferencing operator, what about the -> ? What's the difference?


回答1:


a->b is a syntactic sugar for (*a).b

The only special case is the object operator-> which is called when -> is used on an object. It can be used to "simulate" the object is a pointer ( as with smart references )




回答2:


In the absence of overloading operator->, p->x is equivalent to (*p).x



来源:https://stackoverflow.com/questions/7681926/c-pointers-difference-between-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!