【问题标题】:Is It possible to create class name starts with digits in c++ [duplicate]是否可以在c ++中创建以数字开头的类名[重复]
【发布时间】:2019-06-12 05:56:23
【问题描述】:

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

【问题讨论】:

标签: c++


【解决方案1】:

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

引用标准,第 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-nondigitidentifier 的所有派生中必须在digit 之前。因此,标识符不能以数字开头。

【讨论】:

  • 指出所提到的部分/如何暗示数字/阿尔法将结束这一点。
  • 是的,我正在寻找报价 ;)
  • 你也可以引用lex.name,它描述了标识符的语法。
猜你喜欢
  • 2018-10-19
  • 2021-12-29
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-24
  • 2011-01-18
相关资源
最近更新 更多