How can I use covariant return types with smart pointers?

后端 未结 7 1555
囚心锁ツ
囚心锁ツ 2020-11-27 17:42

I have code like this:

class RetInterface {...}

class Ret1: public RetInterface {...}

class AInterface
{
  public:
     virtual boost::shared_ptr

        
7条回答
  •  执念已碎
    2020-11-27 18:16

    maybe you could use an out parameter to get around "covariance with returned boost shared_ptrs.

     void get_r_to(boost::shared_ptr& ) ...
    

    since I suspect a caller can drop in a more refined shared_ptr type as argument.

提交回复
热议问题