首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

C++中的swich只支持数字吗?解决思路

2012-03-29 
C++中的swich只支持数字吗?在switch()中只有写数字或者char才可以,否则就提示不是integer类型,这是为什么,

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、枚举存储的变量也是整数

热点排行