运行时错误:terminate called after throwing an instance of 'std::bad_weak_ptr'what(): bad_weak_ptr, Aborted (core dumped)
报这个错的原因是类Session
继承了std::enable_shared_from_this<Session>
,其构造函数中尚未初始化*this
,但是在构造函数中调用了shared_from_this()
,将其初始化逻辑移到单独方法即可解决
class Session: public std::enable_shared_from_this<Session>{
public:
Session(){
auto self = shared_from_this();
}
}