DEV Community

Discussion on: Memory management using Smart Pointers in C++ - Part 2

Collapse
sandordargo profile image
Sandor Dargo

What should be made clear IMO is that there is no good reason to pass a smart pointer by reference.

If you refer to Herb Sutter, he recommends that you "don’t pass a smart pointer as a function parameter unless you want to use or manipulate the smart pointer itself, such as to share or transfer ownership".

Consider that and knowing that sharing a smart pointer by reference doesn't share or transfer the ownership, we have no reasons to pass a SP by reference.

Some corresponding rules:

isocpp.github.io/CppCoreGuidelines...
isocpp.github.io/CppCoreGuidelines...