来自ISO C ++草案(n3290)的一点:3.4.3.2/1命名空间成员 [英] A point from the ISO C++ draft (n3290): 3.4.3.2/1 Namespace members

查看:96
本文介绍了来自ISO C ++草案(n3290)的一点:3.4.3.2/1命名空间成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自ISO C ++草稿(n3290)的一点:3.4.3.2/1命名空间成员

A point from the ISO C++ draft (n3290): 3.4.3.2/1 Namespace members


如果嵌套名称说明符of qualified-id提名命名空间,
在命名空间的范围
中查找嵌套名称说明符之后指定的名称。 如果限定ID以::开头,则在全局命名空间中查找::后的
名称。在
情况下,在发生整个后缀表达式的上下文中查找模板id的模板参数中的名称

这里可以解释一下BOLD部分....和从早期的c ++ 03草稿到c ++ 0x草案他添加了

Here can any one explain about the BOLD part .... and from earlier c++03 draft to c++0x draft he added


如果一个限定id以::开头,那么在全局命名空间中查找
之后的名字。 strong>

If a qualified-id starts with ::, the name after the :: is looked up in the global namespace.

可以用示例程序解释

推荐答案

:: S 是合格的ID。

id :: S :: f S :: 是嵌套名称说明符。

In the qualified-id ::S::f, S:: is a nested-name-specifier.

在非正式术语中,嵌套名称说明符是

In informal terms, a nested-name-specifier is the part of the id that


  • 开头的id的一部分在限定id的开始处或在初始范围解析算子(::)之后,如果在id的开始处出现,并且

  • 以最后一个范围解析算子in the qualified-id。

非正式地,ID是限定ID或非限定ID。如果id是一个限定id,它实际上由两部分组成:一个嵌套名称说明符后面跟一个非限定id。

Very informally, an id is either a qualified-id or an unqualified-id. If the id is a qualified-id, it is actually composed of two parts: a nested-name specifier followed by an unqualified-id.

给定:

struct  A {
    struct B {
        void F();
    };
};




  • A 是无限定ID。

  • :: A 是限定ID,但没有嵌套名称说明符。

  • A :: B 是合格的id, A :: -name-specifier。

  • :: A :: B 是合格的ID, A :: 是一个嵌套名称说明符。

  • A :: B :: F id和 B :: A :: B :: 都是嵌套名称说明符。
  • :: A :: B :: F 是合格的ID,并且 B :: A :: B :: 是嵌套名称说明符。

    • A is an unqualified-id.
    • ::A is a qualified-id but has no nested-name-specifier.
    • A::B is a qualified-id and A:: is a nested-name-specifier.
    • ::A::B is a qualified-id and A:: is a nested-name-specifier.
    • A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.
    • ::A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.
    • 另一个例子:

      #include <iostream>
      using namespace std;
      
      int count(0);                   // Used for iteration
      
      class outer {
      public:
          static int count;           // counts the number of outer classes
          class inner {
          public:
              static int count;       // counts the number of inner classes
          };
      };
      
      int outer::count(42);            // assume there are 42 outer classes
      int outer::inner::count(32768);  // assume there are 2^15 inner classes
                                       // getting the hang of it?
      
      int main() {
          // how do we access these numbers?
          //
          // using "count = ?" is quite ambiguous since we don't explicitly know which
          // count we are referring to.
          //
          // Nested name specifiers help us out here
      
          cout << ::count << endl;        // The iterator value
          cout << outer::count << endl;           // the number of outer classes instantiated
          cout << outer::inner::count << endl;    // the number of inner classes instantiated
          return 0;
      }
      

      编辑:

      为了回应你的意见,我相信这个语句只是意味着一个模板的参数被处理的上下文和它们被声明的行。例如, f。〜foo(); 中的

      In response to your comment, I believe that statement simply means that the arguments of a template are handled w.r.t the context and line by which they are declared. For example,

      ,foo会在 f。,并且在 foo< int> 的范围内,使用 foo

      in f.~foo();, foo is looked up within f., and within the scope of foo<int>, it is valid to refer to it just with with foo.

      这篇关于来自ISO C ++草案(n3290)的一点:3.4.3.2/1命名空间成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆