Turning off C++ casting?
Vladimir Merzliakov
wanderer@rsu.ru
Thu Feb 20 12:21:00 GMT 2003
>> | assert (dynamic_cast<ExtendedObject*>(&baseObj) != NULL);
>> | ExtendedObject& obj = *reinterpret_cast<ExtendedObject*>(&baseObj);
>>
>> Please write the last line as
>>
>> ExtendedObject& obj = *dynamic_cast<ExtendedObject*>(&baseObj);
>
>Why? The point was to avoid the performance impact (assuming there is) of
>dynamic_cast in non-debugging releases. After the dynamic_cast has been
>checked to be valid, you can use the faster reinterpret_cast safely, can't
>you?
I think expression:
(dynamic_cast<T*>(v)==0 || dynamic_cast<T*>(v)==reinterpret_cast<T*>(v))
can be false in case multiply inheritance and virtual inheritance.
Vladimir
More information about the Gcc
mailing list