开发者

c++ syntax of create an instance

开发者 https://www.devze.com 2023-01-19 19:57 出处:网络
class class_name instance; class开发者_如何学JAVA_name instance; The above all work with cl.exe, but is it standard,is it the same with all other compilers?class class_name instance; is allowed by
class class_name instance;

class开发者_如何学JAVA_name instance;

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


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 ;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消