Pass by reference vs. Pass by shared_ptr
c++, c++11, shared-ptr
Solution
You only pass the `shared_ptr` to a function if the function cares about there being a `shared_ptr`, usually because it wants to keep a copy, or a `weak_ptr`.
Anything else just reduces applicability of the function for no gain.
Problem
Most questions on Stackoverflow are asking about shared_ptr should be passed by ref or by value. However my question is exampled like this: ``` class Foo; void function1(Foo & ff) { ff.m_abc = 1024; } void function2(const std::shared_ptr<Foo> & ff) { ff->m_abc = 1024; } ``` The `function1` and `function2` may use and change some part of ff. My case here: I have a need for calling a function with an arg `*this` or `shared_from_this()`. ``` print(msg, *this); or print(msg, this->shared_from_this()); ``` I can either use `function1` or `function2` style in my code for a function. However, if I use `function2` style, I need to implement `Foo` to inherit from `std::enable_shared_from_this`, but with `function1` style, I do not need to. I'm using this function in a single-threaded environment