This post is just to know is there any alternate way from using dynamic_cast.
Is it supported in C++?
I tried with little program but it failed, can anyone direct me what could be
the problem in below code?
Note: 1. This code is not getting compiled.
2. Gcc compiler is used for the compilation.
3. This code doesn't give any meaningfull implementation, it was
just written, to find alternate way of doing dynamic_cast.
it knows to look at Base's declaration of getPointer() since bPtr is a pointer to a Base. It does not know
that bPtr is actually a pointer to a Derived, and therefore it does not look at Derived's declaration of
getPointer(). According to inheritance rules, Derived is-a Base, but the converse is not necessarily true;
hence the need for dynamic_cast.
Avoiding dynamic_cast's in C++ requires modification of design; there is no syntactic way to accomplish
it. If there is a specific case of dynamic_cast you are trying to avoid, you'll need to post the actual case/code.
jsmith, I realized what you said. Compiler sees the static type of bptr during compilation, which is Base* and bptr points to Derived object during run-time.