Iterate through struct variables

后端 未结 4 574
孤独总比滥情好
孤独总比滥情好 2020-12-11 08:00

I want to get an iterator to struct variable to set a particular one on runtime according to enum ID. for example -

struct {
char _char;
int _int;
char* pcha         


        
4条回答
  •  情深已故
    2020-12-11 08:47

    Nope. In C++ you normally do something like this for enums:

    enum VarTypes {
     vtChar = 0,
     vtInt,
     vtDouble,
    
     vtFirst = vtChar,
     vtLast = vtDouble
    };
    

    You would still need a switch block to set the members on the struct. If you feel so inclined have a look at some Variant implementation in Microsoft's code. That's kinda similar to what you are doing.

提交回复
热议问题