c++ - SmartPointer : cast between base and derived classes -
say have function :
smartptr<a> dosomething(smartptr<a> a); and classes :
class { } class b : public { } and :
smartptr<a> foo = new b(); dosomething(foo); now, smartptr<b> object dosomething.
smartptr<b> b = dosomething(foo); is possible ? kind of casting have ?
right now, found believe ugly :
b* b = (b*)dosomething().get() important notes : not have access smartptr , dosomething() code.
instead of doing that, can :
b *b = dynamic_cast< b* >( dosomething.get() ); but have check if b null.
Comments
Post a Comment