Suppose I'm given a C++ library full of inheritance. I'm given a Base*
in a function when I know that it is actually pointing to a Derived
object and Derived
inherits Base
. But I don't know what kind of inheritance it is (public/protected/private). I also don't know if there is any virtual function in the hierarchy.
Given this situation, without looking into the source code/documentation of Base
and Derived
, which cast should I use? Or should I consult the code/documentation first to ensure about polymorphism?
Background
I am writing changeEvent
function of QMainWindow
in Qt 4.7. The changeEvent
function takes QEvent*
which I can cast to other type by knowing QEvent::type()
. I was wondering if I should use static_cast
or dynamic_cast
.
Thanks.