what's the point of std::unique_ptr::get

前端 未结 6 1968
半阙折子戏
半阙折子戏 2020-12-04 21:45

Doesn\'t std::unique_ptr::get defeat the purpose of having a unique_ptr in the first place? I would have expected this function to change its state so it holds

6条回答
  •  我在风中等你
    2020-12-04 21:57

    std::unique_ptr provides unique ownership semantics safely. However that doesn't rule out the need for non-owning pointers. std::shared_ptr has a non-owning counterpart, std::weak_ptr. Raw pointers operate as std::unique_ptr's non-owning counterpart.

提交回复
热议问题