Turning off C++ casting?
Paolo Bonzini
paolo.bonzini@polimi.it
Thu Feb 20 12:56:00 GMT 2003
On Thursday 20 February 2003 13:17, Gabriel Dos Reis wrote:
> Paolo Bonzini <paolo.bonzini@polimi.it> writes:
> | The point was to avoid the performance impact (assuming there is) of
> | dynamic_cast in non-debugging releases.
>
> If you know for sure that the derivation actually holds, then use
> static_cast<>, -not- reinterpret_cast<>.
You do because of the assert. So the correct answer to the poster's question
is to use
assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
ExtendedObject& obj = *static_cast<ExtendedObject*>(&baseObj);
Paolo
More information about the Gcc
mailing list