有工会成员的结构是否有资格成为 POD?
Can a structure with union members be qualified as POD?
可以这样构造MyWrapStruct:
struct MyWrapStruct
{
bool myBool;
union
{
struct
{
void* myPtr;
int myInt;
};
Struct1 myStruct1;
Struct2 myStruct2;
} myStructs;
};
与"sub-structures" :
struct Struct1
{
void* myPtr;
int myInt;
float mySpecialFloat;
};
struct Struct2
{
void* myPtr;
int myInt;
int mySpecialInt;
};
算不算POD结构?
是 - 甚至联合类型也只包含数据,没有方法、构造函数等。
参见:
What are POD types in C++?
更新
当然前提是union只包含POD类型。
参见:
Questions regarding C++ non-POD unions
可以这样构造MyWrapStruct:
struct MyWrapStruct
{
bool myBool;
union
{
struct
{
void* myPtr;
int myInt;
};
Struct1 myStruct1;
Struct2 myStruct2;
} myStructs;
};
与"sub-structures" :
struct Struct1
{
void* myPtr;
int myInt;
float mySpecialFloat;
};
struct Struct2
{
void* myPtr;
int myInt;
int mySpecialInt;
};
算不算POD结构?
是 - 甚至联合类型也只包含数据,没有方法、构造函数等。
参见:
What are POD types in C++?
更新 当然前提是union只包含POD类型。
参见:
Questions regarding C++ non-POD unions