error C2051: case expression not constant ?
来源:互联网 发布:php 代码加密 编辑:程序博客网 时间:2024/05/17 00:58
今天编程。在键盘响应函数里需要用到下面的函数,
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case "s":
case "S":
angleX +=15.0;
glutPostRedisplay();
break;
case "d":
case "D":
angleY += 15.0;
glutPostRedisplay();
break;
case 27: //即键盘左上角的esc
exit(0);
break;
}
}
在VC里编译时,出现 error C2051: case expression not constant。
我想不至于呀, case "s":
case "S": 明明就是常量嘛,字符嘛。
在网上搜了半天,发现了case表达式还真有问题 ,
比如 's'才是常量(单引号) ,"s" 这样就是字符串了(双引号)。
所以解决方法是把所有的case 表达式里面的双引号换成单引号如下:
void keyboard(unsigned char key, int x, int y)
{ switch (key)
{ case 's':
case 'S':
angleX +=15.0;
glutPostRedisplay();
break;
case 'd':
case 'D':
angleY += 15.0;glutPostRedisplay();
break;
case 27: //即键盘左上角的esc
exit(0);
break;
}
编译成功!
本来以前解决过这个问题,用时又想不起来了,今天又遇到,所以专门记下来,以备后用!
- error C2051: case expression not constant ?
- 编译问题 case expression not constant
- 编译问题 case expression not constant
- Keil提示错误error c221: non-constant case/dim expression
- switch case constant expression required
- constant expression required-case后参数报错
- .size expression for apf_page_fault does not evaluate to a constant
- size expression for do_hypervisor_callback does not evaluate to a constant
- size expression for do_hypervisor_callback does not evaluate to a constant
- error: ‘__u32 __fswab32(__u32)’ cannot appear in a constant-expression
- error C2099: initializer is not a constant
- error: initializer element is not constant
- error C2099: initializer is not a constant
- error C2099: initializer is not a constant
- debug03:“case expressions must be constant expression”报错的破解
- Error处理:Java switch case 报错:case expressions must be constant expressions
- !!!Constant Expression (From MSDN)
- Constant expression required
- JAVA中如何输入整数例如(1,2,3,4,5)详细解析
- 使用hibernate构造hql语句时order by的妙用
- 《程序.花开百味》雷伟.著
- 设计一个个人纳税计算程序
- CvMat的声明及元素访问总结
- error C2051: case expression not constant ?
- 希尔排序(shell sort)
- 图解ARM-Linux的启动全过程
- ruby on rails不错的几个视频网站
- Oracle 远程连接问题
- 【CSS笔记之六】filter滤镜在IE浏览器失效的原因、Chrome不认document.documentElement.scrollTop的解决方法
- Android系统Recovery工作原理1-- 升级包 的 制作
- 程序员我也得会修电脑
- DM365+EC122调试(一)