在一个union
中的不同匿名结构中具有相同名称的字段合法吗?
union Foo
{
struct
{
int bar;
};
struct
{
int bar;
};
};
MSVC实际上允许这样做,而GCC不允许。
答案 0 :(得分:4)
代码无效,仅是因为C ++没有匿名结构。
使用-pedantic-errors
,GCC拒绝使用error: ISO C++ prohibits anonymous structs [-Wpedantic]
进行编译。