
Jim, "Jim.Hyslop" <jim.hyslop@leitch.com> a écrit dans le message de news: F5DF799F740CD611802200034722783C73664E@pelican.mars.leitch.com...
Jean Llorca (yg-boost-users@gmane.org) 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
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 =
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. polymorphic_upcast<A*>( x ); Jean.