shared_from_this bad_weak_ptr的原因

原因:创建类A的对象的时候没有用智能指针包裹,而是直接new的裸指针。

enable_from_this 的使用与实现原理说明:

shared_from_this()是enable_shared_from_this<T>的成员函数,返回shared_ptr<T>;
注意的是,这个函数仅在shared_ptr<T>的构造函数被调用之后才能使用。
原因是enable_shared_from_this::weak_ptr并不在构造函数中设置,而是在shared_ptr<T>的构造函数中设置。
原文地址:https://www.cnblogs.com/amwuau/p/9287336.html