0
class class_name instance;

class_name instance;

The above all work with cl.exe, but is it standard,is it the same with all other compilers?

2 Answers 2

3

class class_name instance; is allowed by the elaborated-type-specifier nonterminal in the C++ grammar. It's hard to point to a particular section of the standard that tells you this, since even in the appendix that gives the C++ grammar it's rather spread out, but the production basically goes (with many steps elided):

declaration-statement
    -> type-specifier declarator ;
    -> elaborated-type-specifier declarator ;
    -> class identifier declarator ;
    -> class identifier unqualified-id ;
    -> class class_name instance ;

class_name instance ;, in comparison, is produced using the simple-type-specifier non-terminal.

declaration-statement
    -> type-specifier declarator ;
    -> simple-type-specifier declarator ;
    -> type-name unqualified-id ;
    -> class_name instance ;
Sign up to request clarification or add additional context in comments.

Comments

2

Yes, It's standard and means the same thing. class T and T mean the same thing in C++. The syntax comes from C where struct T and T don't mean the same thing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.