News for hackers. Stuff that matters.
Re:Writing comments about pointer ownership by bluecmd on Sunday August 23, 2015 @03:22AM (#10104923)
Why not use shared_ptr in this case? Why enforce single ownership?
Re:Writing comments about pointer ownership by nice_byte on Sunday August 23, 2015 @03:43AM (#10104956)
Because the example is about an idiomatic way of enforcing exclusive pointer ownership. Maybe it wasn't a very good example though. A better example might be this: in the Builder design pattern, an object is built from various "parts" by the client. It's obvious that the object should have an exclusive ownership of all of its parts. However, at the time of creation, each part belongs to whoever created it, so the ownership needs to be transferred.
Re:Writing comments about pointer ownership by malkia on Sunday August 23, 2015 @03:40AM (#10104950)
You also need week_ptr, that holds a pointer for a week... just kidding...

But often you need weak_ptr, for caches - where shared_ptr won't free it, and unique_ptr won't allow it to be shared.