How can I call a private destructor from a shared_ptr?

后端 未结 2 1955
清歌不尽
清歌不尽 2020-12-30 11:39

I have a resource_manager class which maintains a std::vector > internally. resource_manager i

2条回答
  •  余生分开走
    2020-12-30 12:03

    Perhaps declare shared_ptr as a friend? shared_ptr doesn't call the constructor, and should only destruct if your resource manager releases the pointer before all clients have destroyed their shared_ptrs. This won't allow clients to break the protection, but will allow clients to keep a resource alive against the resource_manager's "will."

提交回复
热议问题