26 Aug
2002
26 Aug
'02
3:18 p.m.
Thank you,
struct C : public BaseC { C() : b( new B("C::b") ) { } void set(const boost::shared_ptr<A>& ptr) { b.swap( boost::shared_static_cast<B>( ptr ) ); // L21 } void print() { std::cout << b->name << std::endl; } boost::shared_ptr<B> b; };
Why not simply
b = boost::shared_static_cast<B>( ptr );
or
b = boost::shared_polymorphic_cast<B>( ptr );
I want to swap the pointers inside for further use (for saving the old ptr contents and restoring for circumstances - clone() may be one way before set() it but has overhead). Regards Olaf