Turning off C++ casting??

Mongryong Mongryong@sympatico.ca
Wed Feb 19 23:43:00 GMT 2003


On Wed, 2003-02-19 at 18:17, Jack Lloyd wrote:
> In the case of dynamic_cast, this would be a tremendously bad idea. The
> reason dynamic_cast is so useful is because it allows you to do a cast even
> when you're not sure that the cast is correct; the dynamic_cast will test
> it for you. Replacing dynamic_cast with a static cast would cause all sorts
> of messes, given most uses of dynamic_cast. The other cast operations are
> just as cheap as a C-style cast, so it's a non-issue.
> 
 Sure, it's generally a bad idea.  But if I'm iterating over lots of
objects, I'd like to get rid off the cost of dynamic_cast when I know
for sure the objects will always be of this type.  Dynamic casting is
expensive when iterating lots of objects!  I can manually do it using my
own dynamic_cast, but I would like to know if there's a nicer way to do
by simply 'telling' dynamic cast to always perform the cast.

Maybe a better question would be:  "Can I override the C++ dynamic_casts
like I can the new and delete operators?"





More information about the Gcc mailing list