tr1::bad_weak_ptr
AuthConnection::AuthConnection(boost::asio::io_service& io_service)
:Connection(io_service)
{
boost::shared_ptr<AuthHandler>h (new AuthHandler( shared_from_this() ));
this->handler=h;
}
shared_from_this() 应该返回Connection 的 ptr ,但它抛出了这个异常,
tr1::bad_weak_ptr
我不知道这里出了什么问题!
Possible Duplicate:
enable_shared_from_this - empty internal weak pointer?
AuthConnection::AuthConnection(boost::asio::io_service& io_service)
:Connection(io_service)
{
boost::shared_ptr<AuthHandler>h (new AuthHandler( shared_from_this() ));
this->handler=h;
}
shared_from_this() should return a ptr of Connection , but it's throwing this exception
tr1::bad_weak_ptr
i dont have a clue what's wrong here!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您对
shared_from_this()
的使用是错误的。它应该在类中使用,如下所示:
然后您可以调用
y->f()
来获取该类的this指针。不仅仅是这个,实际问题在 this 问题与解答。这与您无法在派生对象的构造函数中调用
shared_from_this()
的事实有关。I'm guessing your usage of
shared_from_this()
is wrong.It should be used in a class as follows:
Then you can call
y->f()
to get the this pointer of the class.It's more then merely this, the actual issue is explained in this question and answer. It has to do with the fact that you can't call
shared_from_this()
in the ctor of the derived object.