Are there any downsides with using make_shared to create a shared_ptr

前端 未结 5 862
栀梦
栀梦 2020-12-12 20:33

Are there any downsides with using make_shared() instead of using shared_ptr(new T).

Boost documentation states

5条回答
  •  再見小時候
    2020-12-12 21:05

    Additionally, make_shared is not compatible with the factory pattern. This is because the call to make_shared within your factory function calls the library code, which in turn calls new, which it doesn't have access to, since it cannot call the class's private constructor(s) (constructor(s) should be private, if you follow the factory pattern correctly).

提交回复
热议问题