Alex Rivera | Logout

static_cast with boost::shared_ptr?

Asked 2009-03-09T02:47:21.667
74

What is the equivalent of a static_cast with boost::shared_ptr?

In other words, how do I have to rewrite the following

Base* b = new Derived();
Derived* d = static_cast<Derived*>(b);

when using shared_ptr?

boost::shared_ptr<Base> b(new Derived());
boost::shared_ptr<Derived> d = ???
Edit
Report

1 Answer

3

As a comment: if Derived does in fact derive from Base, then you should use a dynamic_pointer_cast rather than static casts. The system will have a chance of detecting when/if your cast is not correct.

answered 2009-03-09T06:39:58.567

Your Answer