SmacL
SmacL

Reputation: 22932

Unusual scope resolution operator

While refactoring some C++ code today I got some code which boils down to the following

class x
{
  public:
    void x::y();
};

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.

Upvotes: 3

Views: 172

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254631

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();
          ^

The redundant qualifier is disallowed by 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.

with none of those exceptions applying to a member declaration inside its class.

Upvotes: 12

Related Questions