【发布时间】:2012-04-20 12:10:09
【问题描述】:
我偶然在我正在查看的一个源代码中发现了这一点。所以,我在这里给出一个类似的小例子。
在文件test.h中:
#include<iostream>
class test{
int i;
public:
test(){}
//More functions here
};
在文件test.cpp中:
#include "test.h"
int main()
{
test test1;
test::test test2;
test::test::test test3;
return 0;
}
首先,有理由这样声明test2吗?其次,这段代码在 g++ 4.4.3 及更低版本中编译得很好。 C++ 标准中有没有说,当不需要解析作用域时,作用域解析运算符会被忽略?
【问题讨论】: