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>的构造函数中设置。

 

posted @ 2018-07-10 09:44  风来风往风伤(TiAmo)  阅读(1651)  评论(0编辑  收藏  举报