问题描述
今天重构一些C ++代码时,我得到了一些代码,可以归结到以下
While refactoring some C++ code today I got some code which boils down to the following
class x
{
public:
void x::y();
};
x ::
在这里做任何事情,是一个错误,还是别的什么。我最好的猜测是,它是一个人工制品留下了一些自动完成,但我很好奇,知道我是否错过任何东西。正在使用的编译器是VS2010 SP1。
Does the x::
scope resolution operator do anything here, is it a bug, or is it something else. My best guess is that it is an artefact left over by some autocomplete but I'm curious to know if I'm missing anything. Compiler in use is VS2010 SP1.
推荐答案
这是一个错误,大多数编译器会拒绝它。例如,
It's a bug, and most compilers will reject it. For example, GCC says
prog.cpp:4:10: error: extra qualification ‘x::’ on member ‘y’ [-fpermissive]
void x::y();
^
C ++ 11不允许冗余限定符8.3 / 1: p>
The redundant qualifier is disallowed by C++11 8.3/1:
没有任何应用于其类中的成员声明的异常。
with none of those exceptions applying to a member declaration inside its class.
这篇关于不寻常的范围解析操作符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!