I’m trying to override a base class like this in C++
class A:
QWidget *getWidget();
class B: public A:
using A::getWidget;
QWidget *getWidget();
When I try to use this:
A *test = new B();
test->getWidget();
Here, the widget from class A is returned. Is there a way to get widget B? Since I don’t want to start with inspecting my class and casting down to B to get the correct widget, I want to be able to use it similar to the above code snippet. Any suggestions?
First of all, you should declare
getWidget()asvirtualif you want dynamic polymorphic resolution of your function call. That should solve the particular problem you are addressing.Secondly, the
using A::getWidgetis useless, because you are importingA‘s functiongetWidget()into the scope ofB, which already defines a function with the same name and signature.