是否可以在 c++ 中创建以数字开头的类名

Is It possible to create class name starts with digits in c++

本文关键字:开头 数字 c++ 是否 创建      更新时间:2023-10-16

我需要创建一个以数字开头的类名作为206xx.如果可以创建那么如何实现这一点。

不,这是不可能的。有效的标识符必须以非数字字符开头,类名是标识符。

引用标准,第2.10节:

identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit
identifier-nondigit:
nondigit
universal-character-name
other implementation-defined characters
nondigit: one of 
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

标识符是任意长的字母和数字序列。标识符中的每个通用字符名称应指定一个字符,其ISO 10646中的编码属于E.1中指定的范围之一。初始元素不应是通用字符名称,该名称指定其编码属于 E.2 中指定范围之一的字符。大写和小写字母不同。所有字符都很重要。

因此,从上面的语法中,我们看到identifier-nondigit必须在digit之前identifier。因此,标识符不能以数字开头。