How to use a struct inside another struct?

前端 未结 7 1341
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 21:05

I want to use a nested structure but i dont know how to enter data in it, for example:

struct A {
    int data;
    struct B;
};
struct B {
    int number;
};
         


        
7条回答
  •  旧巷少年郎
    2021-02-05 21:15

    struct B {  // <-- declare before
      int number;
    };
    struct A {
     int data;
     B b; // <--- declare data member of `B`
     };
    

    Now you can use it as,

    stage.b.number;
    

提交回复
热议问题