我有一個枚舉類是這樣的:枚舉類「不能轉換爲無符號整型」
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)
?
如果您將「右」類型傳遞給函數(BinaryInstructions),而不是底層(binary_instructions_t),那麼您將不需要轉換。 – 2013-02-19 21:55:00