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 and Derived, with the public inheritance implied by their names, then:
Derived d; Base * b=&d; Base & br = d; will work without any casting whatsoever. When the compiler compiles this code, it has the definitions of classes Base and Derived available, so all the work can be performed at compile time.
template
inline Target polymorphic_upcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) { typedef unsigned int uint;
uint offset = reinterpret_cast<uint>( static_cast
assert( res == dynamic_cast<Target>(x) );
return res; } 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?
-- Jim