没有名字的班级

Ami*_*mar 2 c++ grammar class identifier

我在C++标准文档中读到了关于类的内容:

类是一种类型.它的名称在其范围内成为类名(9.1).

class-name: identifier template-id
Run Code Online (Sandbox Code Playgroud)

我在C++标准中找到了这个标识符的语法:

 2.10 Identifiers
 identifier: nondigit
 identifier nondigit
 identifier digit

 nondigit: one of universal-character-name 
 _ a b c d e f g h i j k l m n o p q r s t u  v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
 digit: one of 0 1 2 3 4 5 6 7 8 9
Run Code Online (Sandbox Code Playgroud)

现在我尝试这样做:

class
{
public:
  int i;
};
Run Code Online (Sandbox Code Playgroud)

它没有任何名称编译好.

任何人都可以给我一个解释吗?是不是违反了为标识符指定的语法?


Nawaz曾就我所提供的代码的标准合规性提出了一个跟进问题.有兴趣的人可以在这里查看.

ava*_*kar 7

语法去了

class-specifier:
    class-head { member-specification_opt }

class-head:
    class-key attribute-specifier-seq_opt class-head-name class-virt-specifier-seq_opt base-clause_opt
    class-key attribute-specifier-seq_opt base-clause_opt

class-key:
    class
    struct
    union
Run Code Online (Sandbox Code Playgroud)

在您的情况下,使用第二次生产class-head- 不class-name涉及.