简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM