C++: syntax for accessing member struct from pointer to class

后端 未结 5 1895
醉话见心
醉话见心 2021-01-18 01:16

I\'m trying to access a member structs variables, but I can\'t seem to get the syntax right. The two compile errors pr. access are: error C2274: \'function-style cast\' : i

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 01:52

    struct Bar{
            int otherdata;
        };
    

    Here you have just defined a structure but not created any object of it. Hence when you say foo.Bar.otherdata = 5; it is compiler error. Create a object of struct Bar like Bar m_bar; and then use Foo.m_bar.otherdata = 5;

提交回复
热议问题