typedef enum{
Adjust_mode_None = 0,
Adjust_mode_H_min,
Adjust_mode_H_max,
Adjust_mode_S_min,
Adjust_mode_S_max,
Adjust_mode_V_min,
Adjust_mode_V_max
}Adjust_mode;
在某些时候我想做:
adjust_mode_ = (adjust_mode_+1)%7;
但是我明白了
Invalid conversion from int to Adjust_mode
这在其他语言中没问题,在 C++ 中有什么问题?我需要定义一些运算符吗?
最佳答案
使用static_cast
。您需要显式转换。
adjust_mode_ = static_cast<Adjust_mode>(adjust_mode_+1)%7;
关于C++ typedef 枚举 : Invalid conversion from int to enum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3861649/