c++ - C++ 标准中 7.1.6.1/1 中的这条语句有什么相关性?

标签 c++ c++11 constants language-lawyer volatile

7.1.6.1/1 包含以下声明(强调我的):

There are two cv-qualifiers, const and volatile. If a cv-qualifier appears in a decl-specifier-seq, the init-declarator-list of the declaration shall not be empty.

上面加粗的语句有什么相关性?换句话说,是否有可能在 decl-specifier-seq 中生成一个 cv-unqualified 类型的示例,其中 init-declarator-list 的声明是空的?

最佳答案

当然,大多数类和枚举定义都使用它:

struct A { }; // valid
const struct B { }; // invalid, const would have no meaning
const struct C { } c { }; // valid

没有别的了。 init-declarator-list 仅用于简单声明,为此,标准 (C++11) 规定:

7 Declarations [dcl.dcl]

3 In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class (Clause 9) or enumeration (7.2), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated-type-specifier with a class-key (9.1), or an enum-specifier.

关于c++ - C++ 标准中 7.1.6.1/1 中的这条语句有什么相关性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27768899/

相关文章:

C++ 重载 = 运算符

c++ - 如何复制类变量并在另一个文件中调用

c++ - 比较两个字符串数组,我的控制台应用程序 "stops responding"

c++ - 我如何优化此代码以这种格式打印?

c++ - 在 C++0x 中忽略收缩转换的后果是什么

c++ - 修改 const 变量值的最简单方法

c++ - 当发生隐式转换时,对象会失去常量性吗?

c++ - 修改窗口的文本框控件的文本

c++ - OpenCV 拟合线异常

c++ - 将 lambda 表达式传递给模板函数时出现编译错误