我有一个这样的枚举类:
typedef unsigned int binary_instructions_t;
enum class BinaryInstructions : binary_instructions_t
{
END_INSTRUCTION = 0x0,
RESET,
SET_STEP_TIME,
SET_STOP_TIME,
START,
ADD
};
我正尝试在这样的 switch 语句中使用枚举的成员:
const std::string& function(binary_instructions_t arg, bool& error_detect)
{
switch(arg)
{
case (unsigned int)BinaryInstructions::END_INSTRUCTION:
return "end";
break;
}
translate_error = true;
return "ERROR";
}
当基础类型已经是 unsigned int
时,为什么需要强制转换为 (unsigned int)
?
最佳答案
那是因为“枚举类”是“强类型”的,所以不能隐式转换为任何其他类型。 http://en.wikipedia.org/wiki/C%2B%2B11#Strongly_typed_enumerations
关于c++ - 枚举类 "could not convert to unsigned int",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14968029/