Boost logo

Boost Users :

From: Jean Llorca (yg-boost-users_at_[hidden])
Date: 2002-06-27 08:38:23


Jim,

"Jim.Hyslop" <jim.hyslop_at_[hidden]> a écrit dans le message de news:
F5DF799F740CD611802200034722783C73664E_at_pelican.mars.leitch.com...
> Jean Llorca (yg-boost-users_at_[hidden]) wrote:
> > I would like to propose, in the spirit of Bjarne Stroustrup book,
> > an upcast (where target inherits source).
> Upcasting is already directly supported by the language. Given classes Base

Here upcasting means casting a base class to a derived class, I know it may seem strange, bust boost offers a downcast
which does the static_cast the language does implicitly already (check <boost/cast.hpp>).

Upcasting is usually achieved by two ways: using reinterpret_cast directly, which is hazardous sometimes because the
pointer to the various base classes are not equal to the derived class when you use multiple inheritance. The other and
only safe way used is to use dynamic_cast.

The code I suggested propose a safe upcast without the constraints of dynamic_cast.

> I don't understand this - how is casting a Target to an unsigned int going
> to help? Did you perhaps mean Target * in the above example, or have I
> missed something?
Yes, target is a pointer type, while Source isn't. That's because of the intended usage of this function which is A* a =
polymorphic_upcast<A*>( x );

Jean.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net