::S
是一個合格的-ID。
在合格代碼::S::f
,S::
是一個嵌套名稱說明符。
在非正式方面,嵌套的名稱說明符是
- 無論是在合格-ID的開始或初步範圍解析運算符(之後開始的ID的一部分:如果:)一個出現在id的最開始處,並且
- 以合格id中的最後一個作用域解析運算符結束。
非常非正式地,id是合格id或非限定id。如果id是一個限定標識符,它實際上由兩部分組成:一個嵌套名稱說明符,後跟一個非限定標識符。
考慮:
struct A {
struct B {
void F();
};
};
A
是不合格的-ID。
::A
是合格的id,但沒有嵌套名稱說明符。
A::B
是一個限定符號,A::
是一個嵌套名稱說明符。
::A::B
是限定符號,A::
是嵌套名稱說明符。
A::B::F
是限定符號,B::
和A::B::
都是嵌套名稱說明符。
::A::B::F
是限定符號,B::
和A::B::
是嵌套名稱說明符。
又如:
#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;
}
編輯:
在回答您的意見,我認爲這種說法只是意味着一個模板的參數進行處理WRT通過上下文和線他們被宣佈。例如,
在f.~foo();
,富時擡頭內f.
,和foo<int>
範圍內,它是有效的參考,它只是與foo
。
這部分怎麼樣「n無論哪種情況,模板id的模板參數中的名稱都會在發生整個postfix-expression的上下文中查找。 ...請說明這一點 – user751747
@user:看我的編輯。 – 2011-08-10 07:12:34