4 ms·
> Also, passing around shared_ptr or unique_ptr in public interfaces puts you in a state of sin. Why is that?
by Aeolos 6y ago
> Also, passing around shared_ptr or unique_ptr in public interfaces puts you in a state of sin.
Why is that?
- ncmncm 6y agoIf they are passed by value or move, you are doing complicated things with ownership that deserve to be encapsulated in a named type. If you are passing them by const reference, you would usually better pass a regular pointer or reference to the pointed-to type. If you are passing them by non-const reference, you have bigger problems. In practice, the new type usually starts out as a PIMPL class with just a std::unique_ptr<impl> member. But often, once the type is named, you discover it is a good place to park more operations.