Hi Amit,

Thanks for your reply.

I digged out google and found out that this kind of conversion(downcasting
from base class to derived class) can lead to unexpected behaviour. However,
I fail to understand how the print function was actually called inspite of
it not being in the base class. I would have expected a run time error
saying that the print() function was not found. Maybe the assembly code
might have the answer for that.

On Fri, Aug 5, 2011 at 1:10 AM, Amit <[email protected]> wrote:

> static_cast<> does not do run time type checking. That's why base
> class  pointer can be changed to drived class though it actually is a
> base class pointer. Now its a drived class pointer, you can call
> drived class functions. If you use dynamic_cast<> instead of
> static_cast<>, it will throw a bad cast exception, because
> dynamic_cast<> does runtime type checking.
>
>  Regards,
>  Amit
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Regards,
Shachindra A C

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to