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

前端 未结 6 1965
半阙折子戏
半阙折子戏 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:53

    The rule I tend to follow is this: if the callee isn't mucking with lifetime/ownership, do not pass it a smart pointer; rather, pass in a raw C++ reference (preferred) or raw pointer. I find it far cleaner and more flexible to separate the concern of ownership from usage.

提交回复
热议问题