今天在重构一些 C++ 代码时,我得到了一些代码,归结为以下内容
class x
{
public:
void x::y();
};
x::
作用域解析操作符在这里做了什么,是一个错误,还是别的什么。我最好的猜测是它是一些自动完成遗留下来的人工制品,但我很想知道我是否遗漏了什么。使用的编译器是VS2010 SP1。
最佳答案
这是一个错误,大多数编译器都会拒绝它。例如,GCC says
prog.cpp:4:10: error: extra qualification ‘x::’ on member ‘y’ [-fpermissive]
void x::y();
^
C++11 8.3/1 不允许冗余限定符:
A declarator-id shall not be qualified except for the definition of a member function or static data member outside of its class, the definition or explicit instantiation of a function or variable member of a namespace outside of its namespace, or the definition of an explicit specialization outside of its namespace, or the declaration of a friend function that is a member of another class or namespace.
没有任何异常(exception)适用于其类内的成员声明。
关于c++ - 不寻常的范围解析运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25975678/