简体   繁体   中英

What is the relevance of this statement in 7.1.6.1/1 in the C++ Standard?

7.1.6.1/1 contains the following statement (emphasis mine):

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 .

What is the relevance of the statement in bold above? In other words, is it possible to produce an example of a cv-unqualified type in a decl-specifier-seq , in which the init-declarator-list of the declaration is empty?

Sure, most class and enum definitions make use of it:

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

There is nothing else. An init-declarator-list is only used in a simple-declaration, and for that, the standard (C++11) states:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM