Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-12-03 10:59:10


Hi,

how can I upcast a shared_ptr?

class Base { /* ... */ }
class Derived : public Base { /* ... */ }

shared_ptr<Base> Get( const char* pName );

shared_ptr<Derived> spDerived = *_cast<*>( Get( "Derived" ) ); // What
do I need to write instead the * ?

Depending on the passed name I like to upcast the returned pointer to a
pointer to the derived class. I used a static_cast with raw pointers
before. What do I have to use with shared_ptr? Do I need to enable RTTI?

Regards,

-Dirk


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