3.3.1 - [basic.scope.pdecl] - 【基本.作用域.声明点】

请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。

3 Basic concepts [basic]

3.3 Declarative regions and scopes [basic.scope]
3.3.1 Point of declaration [basic.scope.pdecl]

 

3 基本概念 【基本】

3.3 定义区域和作用域 【基本.作用域】
3.3.1 声明点 【基本.作用域.声明点】

 

The point of declaration for a name is immediately after its complete declarator (clause 8) and before its initializer (if any), except as noted below. [Example:

    int x = 12;
    { int x = x; }

Here the second x is initialized with its own (indeterminate) value. ]

 

除了下面注解的情况外,某名字的声明点在其声明符(章节 8)完成后立即开始,并在其初始化符之前(如果有的话)。【例:

    int x = 12;
    { int x = x; }

第二个 x 被其自己的值(不确定的)初始化。】

 

[Note: a nonlocal name remains visible up to the point of declaration of the local name that hides it. [Example:

    const int  i = 2;
    { int  i[i]; }

declares a local array of two integers. ]]

 

注:非局部名字保持其可见性直到隐藏它的局部名字的声明点。【例:

    const int  i = 2;
    { int  i[i]; }

声明了一个两个整数的局部数组。】】

 

The point of declaration for an enumerator is immediately after its enumerator-definition. [Example:

    const int x = 12;
    { enum { x = x }; }

Here, the enumerator x is initialized with the value of the constant x, namely 12. ]

 

枚举符的声明点在枚举符定义后立即开始。【例:

    const int x = 12;
    { enum { x = x }; }

此处,枚举符 x 被常数 x 初始化,就是 12。】

 

After the point of declaration of a class member, the member name can be looked up in the scope of its class. [Note: this is true even if the class is an incomplete class. For example,

    struct X {
        enum E { z = 16 };
        int b[X::z];                // OK
    };

--end note]

 

在类成员的声明点之后,该成员名可以在其类作用域中被查找到。【注:即使该类不完整也是如此。例如,

    struct X {
        enum E { z = 16 };
        int b[X::z];                // 可以
    };

--注完

 

The point of declaration of a class first declared in an elaborated-type-specifier is as follows:
  • for an elaborated-type-specifier of the form

        class-key identifier ;

    the elaborated-type-specifier declares the identifier to be a class-name in the scope that contains the declaration, otherwise

  • for an elaborated-type-specifier of the form

        class-key identifier

    if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that contains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest non-class, non-function-prototype scope that contains the declaration. [Note: if the elaborated-type-specifier designates an enumeration, the identifier must refer to an already declared enum-name. If the identifier in the elaborated-type-specifier is a qualified-id, it must refer to an already declared class-name or enum-name. See 3.4.4. ]

 

如下情况,类的声明点由一个详细类型限定词首先声明:
  • 对于具有如下形式的详细类型限定词

        类-关键字 标识符 ;

    详细类型限定词标识符声明为包含该声明的作用域中的一个类-名称,另外

  • 对于具有如下形式的详细类型限定词

        类-关键字 标识符

    如果详细类型限定词在名字空间作用域中定义的函数的声明-限定词-序列参数-声明-子句中出现,则标识符被声明为包含该声明的名字空间中的类-名称;另外,除非作为友元声明,该标识符被声明于不是类作用域,不是函数原型作用域的包含该声明的最小作用域中。【注:如果详细类型限定词指定枚举,则该标识符必须指代已经声明的枚举-名称。如果详细类型限定词中的标识符是一个限定-标识符,它必须指代已经声明的类-名称枚举-名称。参见 3.4.4。】

 

[Note: friend declarations refer to functions or classes that are members of the nearest enclosing namespace, but they do not introduce new names into that namespace (7.3.1.2). Function declarations at block scope and object declarations with the extern specifier at block scope refer to declarations that are members of an enclosing namespace, but they do not introduce new names into that scope. ]

 

【注:对函数或类的友元声明指代其最近的包含其的名字空间中的成员,但它们不向名字空间中引入新的名字(7.3.1.2)。在块作用域中的函数声明和在块作用域中带有 extern 限定词的对象声明指代包含其的名字空间成员,但它们不向该作用域中引入新名字。】

 

[Note: For point of instantiation of a template, see 14.7.1. ]

 

注:模板实例化点,参见 14.7.1。】

 

PREV [basic.scope] | NEXT [basic.scope.local]上一页 【基本.作用域】 | 下一页 【基本.作用域.局部】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值