gpt4 book ai didi

c++ - 为什么这个 const const const 声明有效

转载 作者:IT老高 更新时间:2023-10-28 21:56:11 28 4
gpt4 key购买 nike

friend 让我解释原因

const const const const const int const i = 0;

是有效的语法。我拒绝对这个话题有任何想法。虽然我很好奇它是否只是语法问题?

编辑。标记是 C++,我的 friend 引用了 gcc,所以我应该添加 C 标记。

最佳答案

来自 n1256:

6.7.3/4

If the same qualifier appears more than once in the same specifier-qualifier-list,either directly or via one or more typedefs, the behavior is the same as if it appeared only once.

在 C++ 中,这应该会给出错误。

来自 C++03 标准:

7.1.5/1 [dcl.type]

As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration. The only exceptions to this rule are the following:

— const or volatile can be combined with any other type-specifier. However, redundant cv- qualifiers are prohibited except when introduced through the use of typedefs (7.1.3) or template type arguments (14.3), in which case the redundant cv-qualifiers are ignored.

来自 N3797 (C++11):

7.1.6/2 [dcl.type]

As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailing-type-specifier-seq. The only exceptions to this rule are the following:

— const can be combined with any type specifier except itself.

关于c++ - 为什么这个 const const const 声明有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20551632/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com