这个结构MyWrapStruct可以吗:
struct MyWrapStruct
{
bool myBool;
union
{
struct
{
void* myPtr;
int myInt;
};
Struct1 myStruct1;
Struct2 myStruct2;
} myStructs;
};
具有“子结构”:
struct Struct1
{
void* myPtr;
int myInt;
float mySpecialFloat;
};
struct Struct2
{
void* myPtr;
int myInt;
int mySpecialInt;
};
算不算POD结构?
最佳答案
是的 - 即使 union 类型也只包含数据,没有方法、构造函数等。
参见:
更新 当然,前提是 union 体只包含 POD 类型。
参见:
关于c++ - 具有 union 成员的结构是否符合 POD 资格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50186698/