我偶然在我正在查看的一个源代码中发现了这一点。所以,我在这里给出一个类似的小例子。
在文件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++ 标准中有没有说,当不需要解析作用域时,作用域解析运算符会被忽略?
最佳答案
此代码无效。
它接受代码是 g++ 中的一个错误。见 "g++ does not treat injected class name correctly."该错误已在 2009 年修复,因此应在任何最新版本的 g++ 中修复。
关于c++ - 范围解析运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10050863/