ptr->hello(); /* VERSUS */ (*ptr).hello();

前端 未结 6 1011
无人及你
无人及你 2020-12-02 01:41

I was learning about C++ pointers and the -> operator seemed strange to me. Instead of ptr->hello(); one could write (*ptr).hello();

6条回答
  •  感动是毒
    2020-12-02 02:19

    Others have already answered regarding built-in pointers. With regards to classes, it is possible to overload operator->(), operator&(), and operator*() but not operator.().

    Which means that an object may act differently depending on which syntax you call.

提交回复
热议问题