好问题!我学到了一些新的研究和实验。
你是对你的评论,::S(); //Is ::S a nested name specifier <-- Yes, Indeed!
你会来,当你开始创建命名空间来欣赏它。变量在名称空间中可以具有相同的名称,并且运算符是区分它们的区别。命名空间就像某种意义上的类,是另一层抽象。我不想让你感到名字空间。你可能不欣赏嵌套名指定在这个例子......看看这个例子:我用::count
在那里我可以简单地使用count
#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;
}
通知。 ::count
引用全局名称空间。
你的情况
所以,既然S()是在全局命名空间(即它是在同一个文件或包含的文件或者它不是由namespace <name_of_namespace> { }
笼罩任何一段代码声明,你可以使用new struct ::S
或new struct S
;取其你喜欢。
我刚刚得知这是我很好奇,想回答这个问题,所以如果你有一个更具体的和了解到的答案,请你分享:)
我觉得这个的越多,我越觉得这这不是一个很好的答案。我不知道如何用简单的术语来解释它,但仍然是完全正确的... – 2010-11-05 05:54:12
Little Q:'A :: B' - >我可以说'A'是**排位结构**并且同时'A ::'是一个嵌套名称说明符? – 2012-01-07 16:43:23