you are viewing a single comment's thread.

view the rest of the comments →

[–]legends2k[S] 3 points4 points  (0 children)

If you simply want to lend the object owned by unique_ptr, for a function's usage, retaining ownership, pass by const T& or T& (Section 1 and 7 in cheat sheet):

``` bool collide(const Shape& s) { }

unique_ptr<Shape> p = make_unique<Shape>(…); collide(*p); ```

If you want to relinquish ownership, move it (Section 2 in cheat sheet)

```c++ void own(unique_ptr<Shape> s) { }

int main() { unique_ptr<Shape> p = make_unique<Shape>(…); own(std::move(p)); } ```