Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 769
SmacL Avatar asked Apr 30 '26 13:04

SmacL


1 Answers

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.

like image 129
Mike Seymour Avatar answered May 03 '26 03:05

Mike Seymour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!