Trivial cases of shared_ptr and weak_ptr failing
You must inherit publicly from std::enable_shared_from_this. Inheriting privately doesn’t help – std::shared_ptr can’t access the base class and set it up properly.
You must inherit publicly from std::enable_shared_from_this. Inheriting privately doesn’t help – std::shared_ptr can’t access the base class and set it up properly.
Indeed you are doing it wrong. If you have simple inheritance, just inherit from enable_shared_from this in the base class, and derived class get it for free. (of course you’ll need to downcast the result) If you have multiple inheritance (like it seems), you must use the trick described here and also here : /* … Read more