boost::shared_ptr を使用した static_cast? 質問する

boost::shared_ptr を使用した static_cast? 質問する

static_castと同等のものは何ですかboost::shared_ptr?

言い換えれば、次の文をどのように書き直せばいいのでしょうか

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

使用時shared_ptrは?

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

ベストアンサー1

使用boost::static_pointer_cast

boost::shared_ptr<Base> b(new Derived());
boost::shared_ptr<Derived> d = boost::static_pointer_cast<Derived>(b);

おすすめ記事