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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -