2

C++ newbie here. Is there a way to call an overloaded function in a base class from the same function name with the same signature in a derived class? In Smalltalk, I can do it the "super" keyword. Is there any C++ equivalent?

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

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

Thanks, Norm

2
  • 3
    You already have it in your comment: MyBaseClass::initialize(); Commented Oct 2, 2015 at 15:47
  • you also probably want to do the function virtual - not necessary, but looks like that way to me. Commented Oct 2, 2015 at 15:52

1 Answer 1

1

You literally said the correct syntax in your comment :)

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

class MyDerivedClass : public MyBaseClass {
void initialize() {
    MyBaseClass::initialize(); // first, call MyBaseClass::initialize()
    doLocalInitialize(); // now initialize non-inherited members
}
Sign up to request clarification or add additional context in comments.

1 Comment

Dang, it's that easy? Thanks for the responses.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.