On Thu, Jan 5, 2017 at 1:13 PM, Boris Rasin
Here is how I fixed multiple inheritance problem:
template <typename T> class virtual_shared_from_this : public virtual std::enable_shared_from_this<void> { public: std::shared_ptr<T> shared_from_this() { return std::shared_ptr<T>(std::enable_shared_from_this<void>::shared_from_this(), static_cast
(this)); } }; You use virtual_shared_from_this exactly as you would use enable_shared_from_this. It supports multiple inheritance and is very efficient (no use of dynamic_cast).
This indeed solves the problem of multiple inheritance. But I think I
didn't expose well enough the other problem, which has to do with cyclic
references:
Suppose an object A has a shared_ptr to an object B which has a weak_ptr to
A. Every time this weak_ptr is used, it may not be eligible anymore to
originate a non null shared_ptr. In this case, if B can nicely handle this
locally ( checking the result of weak_ptr