[英]C, Assigning enum to variable using full name
I'm trying to assign an enum value to an enum variable with its "Full" name in c. 我正在尝试将枚举值分配给带有c中“全”名称的枚举变量。 Is this possible?:
这可能吗?:
enum EnumActions{
SHIFT,
REDUCE,
ACCEPT,
GOTO ,
ERROR_A
};
int main(){
enum EnumActions __actionType;
__actionType = EnumActions::SHIFT; //this is giving an error
__actionType = SHIFT;//this works fine
}
any ideas how I can get the first one working? 有什么想法可以使第一个工作吗?
The answer is NO, in C it's not possible. 答案是否定的,在C语言中是不可能的。
You could do it with a C++11 enum class
or with C++ namespace
's: 您可以使用C ++ 11
enum class
或C ++ namespace
:
If you want to make it easier to understand you can use a prefix: 如果您想使其更容易理解,可以使用前缀:
enum EnumActions{
ACTION_SHIFT,
ACTION_REDUCE,
ACTION_ACCEPT,
ACTION_GOTO ,
ACTION_ERROR_A
};
//...
__actionType = ACTION_SHIFT;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.