enum class pid
{
Alpha, Beta, Gamma
};
int main()
{
int propId = 2;
switch(propId)
{
case pid::Alpha:
case pid::Beta:
case pid::Gamma:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的片段在msvc2012中编译好(并且有效),但在clang-3.4和g ++ - 4.8中失败.这些需要static_cast<pid>(propId)在switch子句中使用.
顺便说一句,没有显式转换的简单赋值,例如pid a = propId;在每个编译器中给出错误.
哪一个做对了?