(->) arrow operator and (.) dot operator , class pointer

后端 未结 6 797
粉色の甜心
粉色の甜心 2021-01-31 21:55

In C++ we know that for a pointer of class we use (->) arrow operator to access the members of that class like here:

#include 
usi         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 22:28

    Note that for a pointer variable x

    myclass *x;
    
    • *x means "get the object that x points to"
    • x->setdata(1, 2) is the same as (*x).setdata(1, 2) and finally
    • x[n] means "get the n-th object in an array".

    So for example x->setdata(1, 2) is the same as x[0].setdata(1, 2).

提交回复
热议问题