Unusual scope resolution operator

大憨熊 提交于 2019-12-10 10:17:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25975678/unusual-scope-resolution-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!