Visual Studio 2008-C1017 [英] Visual Studio 2008 - C1017

查看:117
本文介绍了Visual Studio 2008-C1017的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么在此行上得到C1017(无效的整数常量表达式)?

Hi,

Why do I get C1017 (invalid integer constant expression) on this line?

#	if ((bool)1 == (bool)2)



来自MSDN:使用#define定义的常量,如果在#if,#elif或#else指令中使用,则其值必须为整数常量."

操作员不是==这样做吗?

关于



From MSDN: "Constants defined using #define must have values that evaluate to an integer constant if they are used in an #if, #elif, or #else directive."

Doesn''t the operator== do that?

Regards

推荐答案

否.此运算符的值不为整数常量.为什么不获取C ++参考并查看此运算符的作用?我什至羞于解释这一点. :-)但是此错误消息与#define有关,但与#if有关.无论如何,您都不会在示例中使用任何已定义的符号.

而且您编写的表达式不仅对预处理器看起来像胡言乱语.为什么要转换为布尔值?这根本没有意义.我想知道为什么还要使用预处理器?如果确定需要,请先阅读以下内容:
http://www.cplusplus.com/doc/tutorial/preprocessor/ [
No. This operator does not evaluate to an integer constant. Why won''t you get a C++ reference and see what this operator does? I''m even ashamed to explain that. :-) But this error message is about #define, but about #if. You don''t use any defined symbols in your sample anyway.

And the expression you have written looks like gibberish not only to the preprocessor. Why casting to Boolean? It makes no sense at all. And why would you even use the preprocessor, I wonder? If you are sure you need it, read about it first:
http://www.cplusplus.com/doc/tutorial/preprocessor/[^].

—SA


这篇关于Visual Studio 2008-C1017的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆