内容简介:C++编译器将文件代码源文件解析后,将代码分解为在
identifier
C++编译器将文件代码源文件解析后,将代码分解为 identifier
、数值、运算符等,其中 identifier
是由非数字开头、任意字符数字和下划线组成的部分,其用来组成 声明
、 表达式
、 name
和 qualified identifier
。
在 声明
中 identifier
:
- 不能时语法关键字
-
不要以双下划线(
__)或者下划线(_)开头,以免和编译器或者标准库的内部声明冲突,可以参见17.6.4.3 [reserved.names]
identifier
在表达式中除了表示一些简单的函数和对象外,还可以是:
-
the name of an operator function, such as
operator+oroperator new; -
the name of a user-defined conversion function, such as
operator bool; -
the name of a user-defined literal operator function, such as
operator "" _km; -
the character
~followed by class name, such as~MyClass; -
the character
~followed by decltype specifier, such as~decltype(str); -
a
template identifier, such asMyTemplate<int>; -
qualified identifier, such asstd::stringor::tolower.
qualified identifier
qualified identifier
(限定标识符)是由域解析符 ::
标识与 class
名、枚举类名、 namespace
或者 decltype
表达式限定的一类 identifier
。
比如:
std::string::npos ::tolower ::std::cout boost::signals2::connection
name
name
是指下面的一个实体或标签:
-
an
identifier -
操作符函数 (
operator+,operator new); -
用户定义的转换函数
(
operator bool); -
用户定义的字面值转换符
(
operator "" _km); -
模板 id (
name<arg, arg>). -
goto语句指向的label
当编译器遇到一个未知的 name
时,会进行 name lookup
,例如,当编译 std::cout << std::endl;
时:
-
对
std进行unqualified name lookup,发现其是一个声明在头文件<iostream>中的namespace -
对
cout进行qualified name lookup,发现其是一个声明在namespace std中的变量 -
对
endl进行qualified name lookup,发现其是一个声明在namespace std中的函数模板 -
对
<<进行argument-dependent lookup,发现其是一个声明在namespace std中的函数模板声明
其主要规则是,如果目标是一个 qualified identifier
,进行 Qualified name lookup
,否则进行 Unqualified name lookup
,对于函数还可能进行 Argument-dependent lookup
Qualified name lookup
Unqualified name lookup
Argument-dependent lookup
参考
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming Python
Mark Lutz / O'Reilly Media / 2006-8-30 / USD 59.99
Already the industry standard for Python users, "Programming Python" from O'Reilly just got even better. This third edition has been updated to reflect current best practices and the abundance of chan......一起来看看 《Programming Python》 这本书的介绍吧!