std::enable_shared_from_this
enables you to get a validstd::shared_ptr
instance tothis
, when all you have isthis
.Without it, you would have no way of getting a
std::shared_ptr
to this, unless you had already one as a member.
class Y: public std::enable_shared_from_this<Y> {
public:
std::shared_ptr<Y> f() {
return shared_from_this();
}
}
Reference: @1800-information