Sign in to follow this  

dynamic_cast

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i was just wondering what exactly gose on under the hood when you use a dynamic cast? I know that it is a way to get the compiler to accept a child class in place of a parent class but i heard its pretty slow so what exactly goes on? thanks[smile]

Share this post


Link to post
Share on other sites
The short answer is "a hell of a lot".

The long answer is, of course, implementation dependent, but usually involves following the pointer into the vtable and indexing a type information block of some sort. The type information block may contain a tree or list of valid conversions and the pointer patch ups necessary to use them, including the indexing rules to access virtual bases properly. This usually results in a number of string comparisons.

You might be able to follow the disassembly in the your compiler to get a better idea of what happens.

Share this post


Link to post
Share on other sites

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this