在msdn页面上打字“C ++常量表达式”? [英] Typo at msdn page "C++ Constant Expressions"?
问题描述
It says at msdn page for c++ constant expressions that:
非整数常量必须
(显式或
隐式)转换为整数类型为
legal在常数表达式。
因此,下面的代码是
legal:
Nonintegral constants must be converted (either explicitly or implicitly) to integral types to be legal in a constant expression. Therefore, the following code is legal:
const double Size = 11.0;
char chArray[(int)Size];
至少在VC ++ 10.0上,第二行产生:error C2057 :期望常数表达式。
At least on VC++ 10.0 the second line produces: "error C2057: expected constant expression". So is it legal on some other compiler or is the msdn page simply wrong?
推荐答案
根据5.19 / 1:
According to 5.19/1 :
可以
只包含字面值(2.13),
枚举值const
变量或
静态数据成员整数或
枚举类型初始化为
常量表达式(8.5),非类型
模板参数的整数或
枚举类型和sizeof
表达式。 浮动文字
(2.13.3)只有在
转换为积分或枚举
类型时才会出现。
An integral constant-expression can involve only literals (2.13), enumerators,
const
variables or static data members of integral or enumeration types initialized with constant expressions (8.5), non-type template parameters of integral or enumeration types, andsizeof
expressions. Floating literals (2.13.3) can appear only if they are cast to integral or enumeration types.
根据我的理解,代码无效,但以下是合法的:
From my understanding the code is invalid, while the following is legal :
char chArray[(int)11.0];
这篇关于在msdn页面上打字“C ++常量表达式”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!