| foo(const bar&) is ideal if you precisely wish to bar ownership. What? invariably it's more like when) you later decide to share ownership, shared_ptr shouldn't even be necessary for keeping track of single threaded scope based ownership. As for shared_ptrs being very rare, uh, no. We use them by the truckload. To each their own! You might want to look into that, you shouldn't need to count references in single threaded scope based ownership. If you need something to last longer, make it's ownership higher scoped. If something already works it works, but this is not necessary and is avoiding understanding the actual scope of variables. |
The context you're missing is in your post's GP. That poster holds a std::shared_ptr<bar> (for whatever perfectly valid reason) and wishes to pass it to foo(). However, he declares it as foo(const bar &) because the callee does not need to share in the ownership of the shared_ptr. That means it gets called as foo(*p.get()).
> scope based ownership
That's the incorrect assumption that you came to. Obviously if bar is only used for stack-based scope variables, no shared_ptr is needed.