struct in class

前端 未结 6 1184
梦毁少年i
梦毁少年i 2020-12-30 05:09

I have struct in class and not know how to call variables from struct, please help ;)

#include 
using namespace std;

class E
{
public: 
            


        
6条回答
  •  无人及你
    2020-12-30 05:55

    I declared class B inside class A, how do I access it?

    Just because you declare your struct B inside class A does not mean that an instance of class A automatically has the properties of struct B as members, nor does it mean that it automatically has an instance of struct B as a member.

    There is no true relation between the two classes (A and B), besides scoping.


    struct A { 
      struct B { 
        int v;
      };  
    
      B inner_object;
    };
    
    int
    main (int argc, char *argv[]) {
      A object;
        object.inner_object.v = 123;
    }
    

提交回复
热议问题