enum class pid
{
Alpha, Beta, Gamma
};
int main()
{
int propId = 2;
switch(propId)
{
case pid::Alpha:
case pid::Beta:
case pid::Gamma:
break;
}
}
上面的代码片段在 msvc2012 中编译得很好(并且可以工作),但在 clang-3.4 和 g++-4.8 中失败。这些需要static_cast<pid>(propId)
在 switch 子句中使用。
顺便说一句,没有显式转换的简单赋值,例如pid a = propId;
在每个编译器中都会产生错误。
哪一个做对了?