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.