可能重复:
在C中使用枚举类型变量作为字符串的简单方法?
除了手动方式之外,是否有任何将用户输入字符串转换为ENUM值的优雅方式是直接C.
调用以ENUM作为参数的函数的简化示例:
enum = {MONDAY,TUESDAY,WEDNESDAY};
...
//Get user to enter a day of the week from command line
...
//Set the work day according to user input
if (strcmp(user_input,"MONDAY")==0){
SET_WORK_DAY(MONDAY);
} else if (strcmp(user_input,"TUESDAY")==0){
SET_WORK_DAY(TUESDAY);
}
...
Run Code Online (Sandbox Code Playgroud)
谢谢
结构的属性是否在C++中继承
例如:
struct A {
int a;
int b;
}__attribute__((__packed__));
struct B : A {
list<int> l;
};
Run Code Online (Sandbox Code Playgroud)
struct B(struct A)的继承部分是否会继承packed属性?
我不能在没有得到编译器警告的情况下向struct B 添加一个属性((packed)):
ignoring packed attribute because of unpacked non-POD field
Run Code Online (Sandbox Code Playgroud)
所以我知道整个结构B不会打包,这在我的用例中很好,但我要求struct A的字段打包在struct B中.