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

前端 未结 6 1008
无人及你
无人及你 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:15

    They generate the same exact machine code, but for me, ptr->arg() is much easier to read than (*ptr).arg().

提交回复
热议问题