This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Turning off C++ casting?


> |   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?

Paolo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]