dynamic_cast or ordinary cast?

Started by
21 comments, last by Zoomby 20 years, 11 months ago
AP, did you actually try it? How do you think the base classes can both be stored at the same base address? Why am I wasting my time replying to you? These questions, and many more, after these messages!

How appropriate. You fight like a cow.
Advertisement
quote:Surely this must result in two distinct pointer values being printed by the printf call, with an associated calculation being done at runtime


The offset can be calculated at compile time.
quote:Original post by daerid
Hmm... yes, I''ll have to rescind my previous statement. But at the absolute most, all you''ll get is a single pointer addition at runtime. And only when dealing with inheritance in C++.


Inheritance is the only portable example I can come up with, but it''s not safe to assume that pointer adjustment will never be needed in other cases. I would say it''s safe to assume there''s no significant cost involved, although this isn''t guaranteed by the language.

quote:Original post by petewood
The offset can be calculated at compile time.


Yes, but the new pointer value needs to be determined at runtime and so a calculation is required. The cast becomes a lea instruction on my x86 compiler, for example.

This topic is closed to new replies.

Advertisement