编程沉思录

编程沉思录

马上订阅 编程沉思录 RSS 更新: https://www.cyhone.com/atom.xml

从源码角度解读 enable_shared_from_this

2025年1月3日 22:41

我们在使用 C++ 的时候,有时会需要在类的内部获取自身的 shared_ptr,这就会用到 std::enable_shared_from_this。在实际使用过程中,std::enable_shared_from_this 有三个陷阱需要注意:

  1. 不能在构造函数中使用 shared_from_this(), 否则会抛出 std::bad_weak_ptr 异常。对应下面情况...

剩余内容已隐藏

查看完整文章以阅读更多