简体   繁体   中英

How to access and store struct members of vector type?

I have a function in a common module(class) which takes a struct reference of vector type: The structure has an element which is of Vector type.

Please refer following code snippet:

bool getFrameInfo(ABC& abc);

struct ABC {
    int numberOfFrames;
    std::vector<XYZ> framInfo;
    ....
    }

    struct XYZ {
    int size;
    Position Pos;
    ...
    }

I need to access and store members of struct XYZ in member variables or local variables in my class which calls the function defined in the common module to get frame information. Please suggest ways to access and store "XYZ" struct members so that I can use them repeatedly in my program to draw a frame.

Example:

bool getFrameInfo(ABC& abc) {
    abc.framInfo[0].size = 10;
    // more code, where you return something somewhere
}

This will access your vector from abc , then index its first element (I assume it exists), and access the size field of the first struct of your vector. It stores 10 in its size .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM