不寻常的范围解析操作符 [英] Unusual scope resolution operator

查看:139
本文介绍了不寻常的范围解析操作符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天重构一些C ++代码时,我得到了一些代码,可以归结到以下

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

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

x :: 在这里做任何事情,是一个错误,还是别的什么。我最好的猜测是,它是一个人工制品留下了一些自动完成,但我很好奇,知道我是否错过任何东西。正在使用的编译器是VS2010 SP1。

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.

推荐答案

这是一个错误,大多数编译器会拒绝它。例如, GCC说

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

C ++ 11不允许冗余限定符8.3 / 1: p>

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.

这篇关于不寻常的范围解析操作符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆