且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

预处理器“无效的整数常量表达式"被指定为“无效整数常量表达式".比较int和double

更新时间:2023-11-12 20:07:28

错误是因为该语言不允许.

The error is because the language does not permit it.

根据C ++标准, [cpp.cond]/1 :

As per the C++ standard, [cpp.cond]/1:

控制条件包含的表达式应为整数常量表达式.

The expression that controls conditional inclusion shall be an integral constant expression.

不是将 ZOOM_FACTOR 定义为浮点值 1.5 ,而是为什么不将其定义为该值的倍数.例如,与常数 2 相乘,然后进行比较.

Instead of defining ZOOM_FACTOR as floating point value 1.5, why not define it as a multiple of such value. For example, multiply with a constant such as 2 and then make your comparisons.