C++

Asked • 09/01/19

Can I call a base class's virtual function if I'm overriding it?

Say I have classes `Foo` and `Bar` set up like this: class Foo { public: int x; virtual void printStuff() { std::cout << x << std::endl; } }; class Bar : public Foo { public: int y; void printStuff() { // I would like to call Foo.printStuff() here... std::cout << y << std::endl; } }; As annotated in the code, I'd like to be able to call the base class's function that I'm overriding. In Java there's the `super.funcname()` syntax. Is this possible in C++?

1 Expert Answer

By:

Keith B. answered • 09/06/19

Tutor
4.6 (22)

Software Engineer and Math Geek

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.