This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Turning off C++ casting?
On Thursday 20 February 2003 13:17, Gabriel Dos Reis wrote:
> Paolo Bonzini <paolo dot bonzini at polimi dot 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