【发布时间】:2018-11-14 22:15:28
【问题描述】:
在一个 union 内的不同匿名结构中具有相同名称的字段是否合法?
union Foo
{
struct
{
int bar;
};
struct
{
int bar;
};
};
MSVC 实际上允许这样做,而 GCC 则不允许。
【问题讨论】:
-
您这样做的用例是 - 什么?
-
@Neil Butterworth 这实际上是一个意外,因为真实的例子比我在这里提供的更大更复杂
-
禁用
cl(/Za) 的语言扩展并获取:error C2467: illegal declaration of anonymous 'struct'和error C2658: 'Foo::bar': redefinition in anonymous struct/union。
标签: c++