C++箭头成员运算符

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是指向结构的指针,p的值是一个地址,地址无法用点运算符调用结构成员,但是可以用箭头运算符->调用结构成员,就这么简单,一点都不神秘。

猜你喜欢

转载自blog.csdn.net/baidu_38495508/article/details/122388441