具有联盟成员的结构可以被限定为POD吗?

时间:2018-05-05 07:01:26

标签: c++ struct specifications unions pod

这个结构可以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结构?

1 个答案:

答案 0 :(得分:2)

是的 - 甚至联合类型只包含数据,也没有方法,构造函数等。

请参阅:

What are POD types in C++?

<强>更新 当然,只要联合只包含POD类型。

请参阅:

Questions regarding C++ non-POD unions