C++ arrow membership operator

struct somethings{
    
    
    int one;
    int two;
}
int main(){
    
    
    somethings obj={
    
    1,2}
    somethings* p=&obj;
    //obj.one=1
    cout<<obj.one<<endl;
    //p->one=1;
    cout<<p->one<<endl;
    return 0;
}

p is a pointer to a structure, and the value of p is an address. The address cannot use the dot operator to call a structure member, but you can use the arrow operator -> to call a structure member. It's as simple as that, and it's not mysterious at all.

Guess you like

Origin blog.csdn.net/baidu_38495508/article/details/122388441