C++中的swich只支持数字吗?
在switch()中只有写数字或者char才可以,否则就提示不是integer类型,这是为什么,难道就是这样规定的吗?
[解决办法]
msdn对switch的解释:
The switch statement allows selection among multiple sections of code, depending on the value of an integral expression.
switch ( expression )
case constant-expression : statement
[default : statement]
The expression must be of an integral type or of a class type for which there is an unambiguous conversion to integral type. Integral promotion is performed as described in Integral Promotions.
也是就是case 里必须是一个整数,这是语法,是规定。不是整数的,你只能
if
{
}
else if
{
}
else if
{
}
了。
[解决办法]
有序系列的,应该可以,,,如枚举类型的
[解决办法]
是只支持整数,不过BOOL、枚举存储的变量也是整数