3.3.5 - [basic.scope.namespace] - 【基本.作用域.名字空间】

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

3 Basic concepts [basic]

3.3 Declarative regions and scopes [basic.scope]
3.3.5 Namespace scope [basic.scope.namespace]

 

3 基本概念 【基本】

3.3 定义区域和作用域 【基本.作用域】
3.3.5 名字空间作用域 【基本.作用域.名字空间】

 

The declarative region of a namespace-definition is its namespace-body. The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name. Entities declared in a namespace-body are said to be members of the namespace, and names introduced by these declarations into the declarative region of the namespace are said to be member names of the namespace. A namespace member name has namespace scope. Its potential scope includes its namespace from the name's point of declaration (3.3.1) onwards; and for each using-directive (7.3.4) that nominates the member's namespace, the member's potential scope includes that portion of the potential scope of the using-directive that follows the member's point of declaration. [Example:

    namespace N {
        int i;
        int g(int a) { return a; }
        int j();
        void q();
    }
    namespace { int l=1; }
    // the potential scope of l is from its point of declaration
    // to the end of the translation unit

    namespace N {
        int g(char a)               // overloads N::g(int)
        {
            return l+a;             // l is from unnamed namespace
        }

        int i;                      // error: duplicate definition
        int j();                    // OK: duplicate function declaration

        int j()                     // OK: definition of N::j()
        {
            return g(i);            // calls N::g(int)
        }
        int q();                    // error: different return type
    }

--end example]

 

名字空间-定义的声明区域是其名字空间-体。由某原-名字空间-名称指出的潜在作用域,是由该原-名字空间-名称在同一个声明区域中的每个名字空间-定义连接而成的。在名字空间-体中声明的实体被称为该名字空间的成员,这些声明引入的名字被称为该名字空间的成员名称。名字空间成员名称具有名字空间作用域。其潜在作用域包括从其名字的声明点(3.3.1)开始的其所在名字空间;并且对于每个提名了该成员的名字空间的 using-指令(7.3.4),该成员的潜在作用域也包括该成员的声明点后的 using-指令的潜在作用域。【例:

    namespace N {
        int i;
        int g(int a) { return a; }
        int j();
        void q();
    }
    namespace { int l=1; }
    // l 的潜在作用域从其声明点
    // 到这个翻译单元的结尾

    namespace N {
        int g(char a)               // 重载 N::g(int)
        {
            return l+a;             // l 来自匿名名字空间
        }

        int i;                      // 错误:重复定义
        int j();                    // 正确:重复函数声明

        int j()                     // 正确:N::j() 的定义
        {
            return g(i);            // 调用 N::g(int)
        }
        int q();                    // 错误:返回类型不同
    }

--例完

 

A namespace member can also be referred to after the :: scope resolution operator (5.1) applied to the name of its namespace or the name of a namespace which nominates the member's namespace in a using-directive; see 3.4.3.2.

 

名字空间成员还可以通过跟在应用到其名字空间名称,或通过一个 using-指令提名了名字所在的名字空间的名字空间名称的 :: 作用域解析运算符(5.1)后面来指代。

 

A name declared outside all named or unnamed namespaces (7.3), blocks (6.3), function declarations (8.3.5), function definitions (8.4) and classes (clause 9) has global namespace scope (also called global scope). The potential scope of such a name begins at its point of declaration (3.3.1) and ends at the end of the translation unit that is its declarative region. Names declared in the global namespace scope are said to be global.

 

在所有具名或匿名名字空间(7.3),块(6.3),函数声明(8.3.5),函数定义(8.4)和类(章节 9)外声明的名字,具有全局名字空间 作用域(也叫全局作用域)。这种名字的潜在作用域从其声明点(3.3.1)开始,并在作为其声明区域的翻译单元的结尾结束。在全局名字空间中声明的名字被称为全局的

 

PREV [basic.funscope] | NEXT [basic.scope.class]上一页 【基本.函数作用域】 | 下一页 【基本.作用域.类】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值