【发布时间】:2017-05-15 22:01:00
【问题描述】:
我有这样的代码:
struct
{
enum
{
entry,
} en;
} data;
void foo()
{
switch(data.en)
{
}
}
这给了我一个警告:
main.cpp:13:11: warning: enumeration value 'entry' not handled in switch [-Wswitch]
switch(data.en)
这是预期的。我很好奇我是否可以添加case entry: 而不将我的结构命名为一个(这显然有效)。
这个:
struct
{
enum
{
entry,
} en;
} data;
void foo()
{
switch(data.en)
{
case entry:
break;
}
}
给出错误+警告:
main.cpp: In function 'void foo()':
main.cpp:15:14: error: 'entry' was not declared in this scope
case entry:
^~~~~
main.cpp:13:11: warning: enumeration value 'entry' not handled in switch [-Wswitch]
switch(data.en)
^
【问题讨论】:
-
里面有问题吗?我没看到。
-
@EOF - 我很好奇是否可以添加案例条目:无需将我的结构命名为 one
-
case entry:代码适用于我当编译为 C 而不是 C++ 时。 -
@MichałWalenciak 你指的是
main.cpp,但标签是C。
标签: c++ gcc struct enums enumeration