Looks like an error in the book ... you definitely must name a type or aliased type (i.e., a typedef
) since C++ is a strongly-typed languages.
Here is what the C++03 specification states on objects, declarations and definitions:
Section 1.8/1:
The properties of an object are determined when the object is created. An object can have a name (clause 3). An object has a storage duration (3.7) which influences its lifetime (3.8). An object has a type (3.9). The term object type refers to the type with which the object is created.
Then in Section 3.1/1:
A declaration is a definition ... [note: the rest of the paragraph are exceptions to this rule and are omitted since they're not applicable in this case]
Then in Section 3.1/6:
A program is ill-formed if the definition of any object gives the object an incomplete type
Finally, in Section 3.9.2/1 it states:
... the term object type (1.8) includes the cv-qualifiers specified when the object is created. The presence of a const specifier in a decl-specifier-seq declares an object of const-qualified object type; such object is called a const object. ...
So according to 3.9.2/1, const
is a qualifier, not a type, and as-such, it has to qualify a valid unqualified type. Secondly, in the example given, according to 3.1/1, the declaration of size
is also a definition, and therefore the size
object must have an associated type or the program is ill-formed according to 3.1/6.