在msdn页面上打字“C ++常量表达式”? [英] Typo at msdn page "C++ Constant Expressions"?

查看:167
本文介绍了在msdn页面上打字“C ++常量表达式”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它在 cdn常量表达式的msdn页面中说: / p>

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, and sizeof 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屋!

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