【发布时间】:2012-10-19 13:08:37
【问题描述】:
我在 C++ 标准文档中读到了这个关于类的内容:
类是一种类型。它的名字在它的内部变成了一个类名(9.1) 范围。
class-name: identifier template-id
我在 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
现在我尝试这样做:
class
{
public:
int i;
};
它编译得很好,没有任何名字。
谁能给我一个解释?是不是违反了为标识符指定的语法?
Nawaz 就我提供的代码的标准合规性提出了后续问题。有兴趣的可以看看here。
【问题讨论】:
-
我想知道您使用的编译器是什么:我无法在 GCC 上编译此代码。
-
@AlbertoMoriconi 我同样使用 QtCreator(en.wikipedia.org/wiki/Qt_Creator),所以我想这也应该使用 GCC。你能发布你得到的错误吗?
-
我收到
error: abstract declarator ‘<anonymous class>’ used as declaration -
@AlbertoMoriconi 请完成编辑,我添加了一个关于后续问题的链接。您的疑问也在其中一个答案中进行了讨论。
标签: c++ class grammar identifier