C++ 标准中 7.1.6.1/1 中的这条语句有什么相关性?
What is the relevance of this statement in 7.1.6.1/1 in the C++ Standard?
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 声明为空?
当然,大多数 class 和枚举定义都使用它:
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.
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 声明为空?
当然,大多数 class 和枚举定义都使用它:
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.