我在头文件中有 enum
。
typedef enum{
up = 8, down = 2, left = 4, right = 6
}direction;
我想使用枚举来识别移动类型。 像这样:
void sayTypeOfMove(int type){
switch(type){
case direction.up:
printf("IT IS UP MOVE...");
break;
}
}
代码编译不通过,问题出在哪里?
最佳答案
当 C 知道您正在处理该枚举时,它就会理解枚举元素,因此正确的代码应该是
void sayTypeOfMove(direction type){
switch(type){
case up:
printf("IT IS UP MOVE...");
break;
}
}
顺便说一句,type
是一个非常糟糕的名字,因为它让人觉得它应该是一个保留关键字。
关于c - 如何在 switch 与 integer using 中使用枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31311145/