::S
は資格-IDでくださいプログラム例で説明することができます。
修飾ID ::S::f
では、S::
はネストされた名前指定子です。非公式の用語で
は、ネストされた名指定子は
- は、資格-IDの先頭にまたは初期スコープ解決演算子(後のいずれかから始まるIDの一部です::)場合1つはIDの冒頭に現れ、
- はqualified-idの最後のスコープ解決演算子で終わります。
非常に非公式には、idはqualified-idまたはunqualified-idです。 idがqualified-idの場合、実際には2つの部分で構成されます。つまり、ネストされた名前の指定子の後ろにunqualified-idが続きます。
は考える:
struct A {
struct B {
void F();
};
};
A
は、修飾されていない-IDです。
::A
は修飾IDですが、ネストされた名前指定子はありません。
A::B
は修飾IDで、A::
はネストされた名前指定子です。
::A::B
は修飾IDで、A::
はネストされた名前指定子です。
A::B::F
は修飾IDであり、B::
とA::B::
の両方はネストされた名前指定子です。
::A::B::F
は修飾IDであり、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;
}
EDIT:
あなたのコメントを受けて、私はその文は、単にWRTにテンプレートの引数が処理されることによって、彼らのコンテキストとラインを意味信じます宣言されている。例えば、
f.~foo();
で、fooがf.
以内に検索され、そしてfoo<int>
の範囲内で、それだけでfoo
とでそれを参照するために有効です。
この部分について「どちらの場合でも、template-idのテンプレート引数の名前は、postfix-expression全体が発生するコンテキストで検索されます。」 ...これも説明してください – user751747
@user:私の編集を参照してください。 –