Yes, the inline declaration is just syntactic sugar. You're forward-declaring that name and using it on the same line.
How is class A * A; declaration parsed by C++?
-
15-07-2023 - |
Question
I'm considering an example from the official spec:
class A * A;
I've read that this line introduces the two names: class A
which can be accessed via elaborated-specifier-type only and pointer to A. Is this line fully equivalent to the two following lines?
class A;
A * A;
Is that line just syntax sugar and actually we have two lines as I've specified above? Or how is class A * A;
parsed by compiler?
Solution
OTHER TIPS
I'm looking for more detailed answer in the working draft N3797 and I've found the following:
§8.3.3:
Thus, a declaration of a particular identifier has the form
T D
whereT
is of the formattribute-specifier-seq_*opt* decl-specifier-seq
andD
is a declarator.
§7.1:
decl-specifier:
storage-class-specifier
type-specifier
function-specifier
friend
typedef
constexpr
decl-specifier-seq:
decl-specifier attribute-specifier-seq_*opt*
decl-specifier decl-specifier-seq
§7.1.6:
type-specifier:
trailing-type-specifier
class-specifier
enum-specifier
§8.3.1:
In a declaration
T D
whereD
has the form* attribute-specifier-seq_*opt* cv-qualifier-seq_*opt* D1
and the type of the identifier in the declarationT D1
is “derived-declarator-type-listT
,” then the type of the identifier ofD
is “derived-declarator-type-list cv-qualifier-seq pointer toT
.”
Now class-specifier
contains class
keyword inside. Hence class A * A
is valid grammar construction, where * A
is declarator.