Boost logo

Boost Users :

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


"Jim.Hyslop" <jim.hyslop_at_[hidden]> a écrit dans le message de news:
> 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 );


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at