How to perform a dynamic_cast with a unique_ptr?

后端 未结 4 883
忘了有多久
忘了有多久 2020-12-15 16:31

I have a class hierarchy as follows:

class BaseSession : public boost::enable_shared_from_this
class DerivedSessionA : public BaseSession
         


        
4条回答
  •  青春惊慌失措
    2020-12-15 17:13

    Simply get the stored pointer using the std::unique_ptr<>::get() method:

    Func(dynamic_cast(shared_from_this().get()))
    

    that if shared_from_this() has that prototype:

    std::unique_ptr& shared_from_this();
    

提交回复
热议问题