有没有一种方法可以在C ++中的类外部调用基本函数? [英] Is there a way to call a base function outside of the class in C++?
问题描述
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?
在这种情况下,您将指定Base::function()
而不是function()
,这将调用覆盖的定义.
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()
在这里做适当的事情来将& derived_object
转换为Base*
然后调用->function()
吗?
Is the appropriate thing to do here to cast & derived_object
as Base*
and then call ->function()
?
感谢您的见识.
推荐答案
尝试derived_object.Base::function();
这篇关于有没有一种方法可以在C ++中的类外部调用基本函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!