简体   繁体   English

不寻常的范围解析运算符

[英]Unusual scope resolution operator

While refactoring some C++ code today I got some code which boils down to the following 在今天重构一些C ++代码的过程中,我得到了一些可归结为以下内容的代码

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

Does the x:: scope resolution operator do anything here, is it a bug, or is it something else. x:: scope解析器操作符是否在此处执行任何操作,是一个错误,还是其他内容。 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. 正在使用的编译器是VS2010 SP1。

It's a bug, and most compilers will reject it. 这是一个错误,大多数编译器都会拒绝它。 For example, GCC says 例如, GCC说

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: 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. 除了在其类之外的成员函数或静态数据成员的定义,在其命名空间之外的命名空间的函数或变量成员的定义或显式实例化,或者显式的定义之外,declarator-id 不应被限定在其命名空间之外的特化,或者是另一个类或命名空间的成员的友元函数的声明。

with none of those exceptions applying to a member declaration inside its class. 没有适用于其类中的成员声明的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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