C++: Creating a shared object rather than a shared pointer to an object

前端 未结 4 1787
无人及你
无人及你 2021-01-19 09:47

boost::shared_ptr really bothers me. Certainly, I understand the utility of such a thing, but I wish that I could use the shared_ptr as an

4条回答
  •  北海茫月
    2021-01-19 10:51

    I'm not sure what this does for you.

    If helpfulContainer.eventHorizon() always deletes its parameter, then why not just pass a new copy of (the original) A class:

      helpfulContainer.eventHorizon(new A(sa1));
    

    Or, if helpfulContainer.eventHorizon() only sometimes deletes its parameter, then making the call as

      helpfulContainer.eventHorizon(new SharedA(sa1)); 
    

    will leak both the SharedA and the original A (sa1) on those occasions when it chooses not to delete.

提交回复
热议问题