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

前端 未结 4 1875
无人及你
无人及你 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:43

    Implicit conversions to the underlying pointer type are inconsistent with the intended use of shared_ptr in that you can extremely easily pass the shared_ptr to a function etc without realizing it.

    It sounds to me like HelpfulContainer is anything BUT helpful and should be fixed or ditched.

    If that's not possible then probably the best way is to just copy the A you want to pass in and pass the copy to the container.

提交回复
热议问题