dimanche 29 mars 2015

What's the reason for the Note in §7.1.3/8 (N4140)?

§7.1.3/8:


[ Note: A typedef-name that names a class type, or a cv-qualified version thereof, is also a class-name (9.1). If a typedef-name is used to identify the subject of an elaborated-type-specifier (7.1.6.3), a class definition (Clause 9), a constructor declaration (12.1), or a destructor declaration (12.4), the program is ill-formed. —end note ] [ Example:



struct S {
S();
~S();
};
typedef struct S T;
S a = T(); // OK
struct T * p; // error


—end example ]


That is, I'd like to know why the snippet below can't compile (live example). Note that the error messages don't say much with the possible exception of the first declaration, struct T * p;.



struct S {};
typedef struct S T;
S s = T(); // OK
struct T * p; // error: elaborated type refers to a typedef
T{}; // error: expected unqualified-id
T::T(){} // error: C++ requires a type specifier for all declarations

Aucun commentaire:

Enregistrer un commentaire