相关疑难解决方法(0)

包含常量成员的POD结构

使用此代码:

struct A
{
    int i;
    const int b;
};

// The union is to verify that A is a type that can be used in a union.
union U
{
    A a;
    int b;
};

int main()
{
    U a = {1, 1};
    U b = {2, 1};
}
Run Code Online (Sandbox Code Playgroud)

g ++版本4.8.3抱怨错误:

a.cpp:9:4: error: member ‘A U::a’ with copy assignment operator not allowed in union
  A a;
    ^
a.cpp:9:4: note: unrestricted unions only available with -std=c++11 or -std=gnu++11
Run Code Online (Sandbox Code Playgroud)

但是clang 3.5.0编译这段代码没有错误.哪一个是正确的?这是编译器错误吗? …

c++ const language-lawyer c++03

11
推荐指数
1
解决办法
876
查看次数

标签 统计

c++ ×1

c++03 ×1

const ×1

language-lawyer ×1