0 or 0L for empty pointers?

Allan Sandfeld Jensen kde at carewolf.com
Fri Jun 23 15:32:22 BST 2006


On Friday 23 June 2006 14:03, Stefan Teleman wrote:
> I think dynamic_cast<> is your friend. It comes with failure guarantee
> which returns NULL for pointers (a Good Thing(TM)). It throws for
> references but then i've rarely seen it used on references anyway.
>
It is _not_ your friend, since you can't trust it. See the other replies.

Even with ways to make it work. It's kinda cryptic and just shouldn't be 
trusted. If you need failure safe type-casting, do your own type-system/use 
Qt's and use static_cast<> (personally I prefer C-casts, but I guess I'm just 
oldfashioned). 

Also while it doesn't cost you very much to use dynamic_cast<>; if you don't 
use it at all, you can disable C++ RTTI and save a lot of memory and speed.

`Allan




More information about the kde-core-devel mailing list