編譯器錯誤 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: ;
}
}