Why do shared_ptr deleters have to be CopyConstructible?

后端 未结 3 1406
盖世英雄少女心
盖世英雄少女心 2021-02-01 14:09

In C++11 std::shared_ptr has four constructors which can be passed deleter objects d of type D. The signatures of these constructors are t

3条回答
  •  难免孤独
    2021-02-01 14:55

    Because shared_ptr are meant to be copied, and any of those copy could have to delete the object, so they must all have access to a deleter. Keeping only one deleter would require, well, refcounting the deleter itself. If you really want that to happen, you could use a nested std::shared_ptr as the deleter, but that sounds a bit overkill.

提交回复
热议问题