Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-09-15 11:29:59


"Thorsten Ottosen" <nesotto_at_[hidden]> writes:

> The following paragraph
>
> -----------
> The C++ built-in dynamic_cast can be used for downcasts and crosscasts of
> pointers to polymorphic objects, but error notification in the form of a
> returned value of 0 is inconvenient to test, or worse yet, easy to forget to
> test. The polymorphic_cast template performs a dynamic_cast, and throws an
> exception if the dynamic_cast returns 0.
>
> -----------
>
> should be extended with:
>
> -------------
>
> Moreover, polymorphic_cast is safer than a dynamic_cast using references
> since it does not need to dereference the pointer. This means that the
> casted pointer can be 0; in this case a dynamic_cast with references will
> result in undefined behavior.
>
> -------------
>
> I've attached the new paragraph in html.
>
>
> Thorsten Ottosen
> ----------------------------
> Dezide Aps
> www.dezide.com
>
>
> <p>The C++ built-in <b>dynamic_cast</b> can be used for downcasts and crosscasts
> of pointers to polymorphic objects, but error notification in the form of a
> returned value of 0 is inconvenient to test, or worse yet, easy to forget to
> test. The <b>polymorphic_cast</b> template performs a <b>dynamic_cast</b>,
> and throws an exception if the <b>dynamic_cast</b> returns 0. Moreover, <b>polymorphic_cast</b> is safer than a <b>dynamic_cast</b> using references since it does not need to dereference the pointer. This means that the casted pointer can be 0; in this case a <b>dynamic_cast</b> with references will result in undefined behavior.</p>
>

I appreciate the effort, but that isn't a patch. A patch (made using
the "diff" tool) would help minimize the effort on the part of the
patcher. Anyway, I made my own change; I hope you like it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk