从派生类

时间:2015-10-02 15:44:43

标签: c++ inheritance

C ++新手在这里。有没有办法从派生类中具有相同签名的相同函数名称调用基类中的重载函数?在Smalltalk中,我可以使用“超级”关键字。有没有C ++等价物?

class MyBaseClass {
  void initialize() { doSomething(); }
};

class MyDerivedClass : public MyBaseClass {
  void initialize() {
      super initialize(); // first, call MyBaseClass::initialize()
      doLocalInitialize(); // now initialize non-inherited members
}

谢谢, 规范

1 个答案:

答案 0 :(得分:1)

你在评论中确实说了正确的语法:)

class MyBaseClass {
    void initialize() { doSomething(); }
};

class MyDerivedClass : public MyBaseClass {
void initialize() {
    MyBaseClass::initialize(); // first, call MyBaseClass::initialize()
    doLocalInitialize(); // now initialize non-inherited members
}