This question is similar, but is about calling the function from inside the class: Can I call a base class's virtual function if I'm overriding it?
In that case, you’d specify Base::function() instead of function(), which will call the overridden definition.
But is there a way to do this outside of the class? My class doesn’t define a copy constructor, so I couldn’t figure out how to cast as the base class:
Base( derived_object ).function()
Is the appropriate thing to do here to cast & derived_object as Base* and then call ->function()?
Thanks for your insight.
Try
derived_object.Base::function();Explanation:
Class::functionis the ‘full name’ of a member function. If you don’t specify theClass::prefix for the function call, it would look up the ‘default’ one (in your case: the derived one).