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