dynamic_cast

Started by
1 comment, last by raptorstrike 19 years, 3 months ago
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]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
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.
i figured it had to be quite a bit. Thanks alot for your fast reply [smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement