Turning off C++ casting?

Gabriel Dos Reis gdr@integrable-solutions.net
Thu Feb 20 10:19:00 GMT 2003


Paolo Bonzini <paolo.bonzini@polimi.it> writes:

| s> 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.
| 
| assert and the pointer version of dynamic_cast are your friends if you don't 
| want #ifdefs.
| 
|   assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
|   ExtendedObject& obj = *reinterpret_cast<ExtendedObject*>(&baseObj);

Please write the last line as

   ExtendedObject& obj = *dynamic_cast<ExtendedObject*>(&baseObj);

-- Gaby



More information about the Gcc mailing list