How to use a struct inside another struct?

前端 未结 7 1332
佛祖请我去吃肉
佛祖请我去吃肉 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:39

    struct TestStruct {
        short Var1;
        float Var2;
        char Var3;
    
        struct TestStruct2 {
            char myType;
            CString myTitle;
            TestStruct2(char b1,CString b2):myType(b1), myTitle(b2){}
        };
    
        std::vector testStruct2;
    
        TestStruct(short a1,float a2,char a3): Var1(a1), Var2(a2), Var3(a3) {
            testStruct2.push_back(TestStruct2(0,"Test Title"));
            testStruct2.push_back(TestStruct2(4,"Test2 Title"));
        }       
    };
    std::vector testStruct;
    
    //push smthng to vec later and call 
    testStruct.push_back(TestStruct(10,55.5,100));
    TRACE("myTest:%s\n",testStruct[0].testStruct2[1].myTitle);
    

提交回复
热议问题