c++ - 不寻常的范围解析运算符

标签 c++ visual-studio-2010 scope

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

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

x:: 作用域解析操作符在这里做了什么,是一个错误,还是别的什么。我最好的猜测是它是一些自动完成遗留下来的人工制品,但我很想知道我是否遗漏了什么。使用的编译器是VS2010 SP1。

最佳答案

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

prog.cpp:4:10: error: extra qualification ‘x::’ on member ‘y’ [-fpermissive]
     void x::y();
          ^

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.

没有任何异常(exception)适用于其类内的成员声明。

关于c++ - 不寻常的范围解析运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25975678/

相关文章:

c++ - 在类中使用指针数组

c++ - C++ 中是否有任何方法可以执行 round(a, n) ?

c++ - 根据中间字母替换(反转)代码

c++ - 为什么 C++ 仍在使用 stdio.h?

c++ - 为什么 `std::unary_function` 仍然在 c++17 中编译?

c++ - 将 LibTiff 安装到 Visual Studio 2010

asp.net-mvc - NuGet 项目 > 添加库包引用未出现

scala - 如何使 sbt 任务使用特定的配置范围?

clojure - 如何在 Clojure 宏的词法范围内捕获?

java - Scala 范围、初始化