Unusual scope resolution operator
While refactoring some C ++ code today, I got a code that boils down to the following
class x
{
public:
void x::y();
};
Is the scope resolution operator x::
doing something here, is it a bug, or is it something else. Your best bet is to assume that this is an artifact left behind by some autocomplete, but I'm curious to know if I'm missing anything. The compiler used is VS2010 SP1.
source to share
This is 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();
^
Reserved qualifier is not allowed C ++ 11 8.3 / 1:
An identifier-identifier must not be qualified , except by defining a member function or static data member outside of its class, defining or explicitly creating a function or namespace variable member outside of its namespace, or defining an explicit specialization outside of its namespace, or declaring a friend function that is a member of another class or namespace.
however, none of these exceptions apply to a member declaration within its class.
source to share