编译器错误 C2450
“type”类型的 switch 表达式是非法的
switch
表达式的计算结果为无效类型。 它必须计算为整数类型或具有明确整数类型转换的类类型。 如果计算结果为用户定义的类型,则必须提供转换运算符。
以下示例生成 C2450:
// C2450.cpp
class X
{
public:
int i;
} x;
class Y
{
public:
int i;
operator int() { return i; } // conversion operator
} y;
int main()
{
switch ( x )
{ // C2450, x is not type int
// try the following line instead
// switch ( y ) {
default: ;
}
}