I have a function which takes a shared_ptr
.
In some member function memfun
of MyClass
, I need to pass this
1) No, it's not impossible to do this without shared_from_this
. You can simply construct a shared_ptr
with a no-op deleter:
void do_nothing(MyClass*) {}
void MyClass:memfun()
{
func(shared_ptr(this, do_nothing));
}
Seeing as you don't actually seem to need shared_from_this
after all, I'm going to skip the next two parts of your question.