关于c ++ 11:标识符是否以根据最新C ++标准保留的下划线开头?

Are identifiers starting with an underscore reserved according to the latest C++ standard?

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
What are the rules about using an underscore in a C++ identifier?

我对本标准的相关章节(如有)感兴趣。


是的,当下划线后接另一个下划线或大写字母(即,对于预处理器定义或宏),或者标识符位于全局命名空间中(§17.6.4.3.2):

Certain sets of names and function signatures are always reserved to the implementation:

— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.

— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

注意,第一点意味着如果标识符中的任何地方出现两个下划线,即使在中间或结尾,名称也会保留。此外,我还要补充(§17.6.4.3.5,重点是我的):

Literal suffix identifiers that do not start with an underscore are reserved for future standardization.


它们不像for那样保留,但您不应该使用它们,因为编译器开发人员可能会使用它们来命名自己的函数,因此它可能与您的函数冲突。因此,如果您使用my_class::_function那么应该没有错误,但是编写一个像void _function()这样的全局函数可能会用一个编译器生成一个副本!