3 Basic concepts [basic]3.3 Declarative regions and scopes [basic.scope]
| 3 基本概念 【基本】3.3 声明区域和作用域 【基本.作用域】
|
Every name is introduced in some portion of program text called a declarative region, which is the largest part of the program in which that name is valid, that is, in which that name may be used as an unqualified name to refer to the same entity. In general, each particular name is valid only within some possibly discontiguous portion of program text called its scope. To determine the scope of a declaration, it is sometimes convenient to refer to the potential scope of a declaration. The scope of a declaration is the same as its potential scope unless the potential scope contains another declaration of the same name. In that case, the potential scope of the declaration in the inner (contained) declarative region is excluded from the scope of the declaration in the outer (containing) declarative region.
| 每个名字都被引入到程序文本中某些被称为声明区域的部分中,声明区域是程序中该名字有效的最广泛区域,也就是说,这个名字在其中可以作为非限定名应用并指代同一个实体。通常情况下,每个特定的名字仅在程序中某些被称为该名字的作用域的不连续区域中有效。为确定一个声明的作用域,通常为方便而提到声明的潜在作用域。声明的作用域与其潜在作用域相同,除非潜在作用域包含相同名字的另一个声明。此时,内部(被包含)的声明区域中声明的潜在作用域被外部(包含的)声明区域中声明的作用域排除。
|
[Example: in
the identifier
| 【例:如下
标识符
|
The names declared by a declaration are introduced into the scope in which the declaration occurs, except that the presence of a friend specifier (11.4), certain uses of the elaborated-type-specifier (3.3.1), and using-directives (7.3.4) alter this general behavior.
| 声明将名字引入该声明发生的作用域中,除非声明具有 friend 限定词(11.4),包含详细类型限定(3.3.1)的特定用法,或使用指令(7.3.4)来改变其一般行为。
|
Given a set of declarations in a single declarative region, each of which specifies the same unqualified name,
[Note: these restrictions apply to the declarative region into which a name is introduced, which is not necessarily the same as the region in which the declaration occurs. In particular, elaborated-type-specifiers (3.3.1) and friend declarations (11.4) may introduce a (possibly not visible) name into an enclosing namespace; these restrictions apply to that region. Local extern declarations (3.5) may introduce a name into the declarative region where the declaration appears and also introduce a (possibly not visible) name into an enclosing namespace; these restrictions apply to both regions. ]
| 若给定某单个声明区域中指定相同非限定名的一组声明,
【注:这些限制应用于名字被引入其中的声明区域,该区域不必和声明发生的声明区域相同。特别地,详细类型限定词(3.3.1)和友元声明(11.4)能够向包含其的名字空间中引入一个(可能不可见)的名字;这些限制就应用到这个区域。局部外部声明(3.5)能够向其所在的声明区域引入名字,也能向包含它的名字空间中引入(可能不可见的)名字;这些限制对这两个区域都有效。】
|
[Note: the name lookup rules are summarized in 3.4. ]
| 【注:3.4 中概述了名字查找规则。】
|
3.3.1 Point of declaration [basic.scope.pdecl]
| 3.3.1 声明点 【基本.作用域.声明点】
|
3.3.2 Local scope [basic.scope.local]
| 3.3.2 局部作用域 【基本.作用域.局部】
|
3.3.3 Function prototype scope [basic.scope.proto]
| 3.3.3 函数原型作用域 【基本.作用域.原型】
|
3.3.4 Function scope [basic.funscope]
| 3.3.4 函数作用域 【基本.函数作用域】
|
3.3.5 Namespace scope [basic.scope.namespace]
| 3.3.5 名字空间作用域 【基本.作用域.名字空间】
|
3.3.6 Class scope [basic.scope.class]
| 3.3.6 类作用域 【基本.作用域.类】
|
3.3.7 Name hiding [basic.scope.hiding]
| 3.3.7 名字隐藏 【基本.作用域.隐藏】
|
PREV [basic.def.odr] | NEXT [basic.scope.pdecl] | 上一页 【基本.定义.ODR】 | 下一页 【基本.作用域.声明点】 |
3.3 - [basic.scope] - 【基本.作用域】
请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。