ollydbg
ollydbg

Reputation: 3525

c++ syntax of create an instance

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?

Upvotes: 0

Views: 238

Answers (2)

outis
outis

Reputation: 77400

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 ;

Upvotes: 3

Yakov Galka
Yakov Galka

Reputation: 72469

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.

Upvotes: 2

Related Questions