这是什么意思?

rai*_*aka 90 c++ syntax

我有2个班:

class base {
    virtual void foo() {};
};

class derived : public base {
    void foo() { base::foo(); }
};
Run Code Online (Sandbox Code Playgroud)

我犯了一个错误并写了base:foo();而不是base::foo();.代码已编译并运行,但是已经过segfaulted.

我不知道我怎么能谷歌它不知道它是什么,但我很感兴趣:这是什么意思?

base:foo();
Run Code Online (Sandbox Code Playgroud)

如果重要的话:

class base : public QAbstractGraphicsShapeItem
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 121

void foo() { base:foo(); }
Run Code Online (Sandbox Code Playgroud)

相当于:

void foo()
{
   base: // An unused label.
   foo(); // Calls the function again, resulting in infinite recursion.
}
Run Code Online (Sandbox Code Playgroud)

由于无限递归,该函数导致堆栈溢出.

  • @Serthy:IIRC Visual Studio为此提供了"在所有控制路径上递归"的警告. (10认同)
  • @Serthy,当我使用`-Wall`时,我收到警告信息:*socc.cc:3:4:警告:标签'base'已定义但未使用[-Wunused-label] base://未使用的标签.* (9认同)