Why shared_ptr has an explicit constructor

前端 未结 5 874
挽巷
挽巷 2020-12-19 17:19

I was wondering why shared_ptr doesn\'t have an implicit constructor. The fact it doesn\'t is alluded to here: Getting a boost::shared_ptr for this

(I f

5条回答
  •  太阳男子
    2020-12-19 17:46

    The logical reason is that:

    • calling the delete operator is not implicit in C++
    • the creation of any owning smart pointer (shared_whatever, scoped_whatever, ...) is really a (delayed) call to the delete operator

提交回复
热议问题