提高shared_from_this&LT;&GT;() [英] boost shared_from_this<>()
问题描述
可能有人在几个简洁的话概括了如何助推 shared_from_this&LT;&GT;()
智能指针应使用,特别是从注册处理在io_service对象使用的角度绑定功能。
could someone summarize in a few succinct words how the boost shared_from_this<>()
smart pointer should be used, particularly from the perspective of registering handlers in the io_service using the bind function.
编辑:一些响应的要求更多内容。基本上,我在寻找陷阱,反直观行为人使用这种机制观察。
Some of the responses have asked for more context. Basically, I'm looking for "gotchas", counter-intuitive behaviour people have observed using this mechanism.
推荐答案
最大的疑难杂症我碰到的是,它是非法的,从构造函数中调用shared_from_this。这直接遵循从一个shared_ptr对象必须存在,你可以调用shared_from_this规则。
The biggest "gotcha" I've run into is that it's illegal to call shared_from_this from the constructor. This follows directly from the rule that a shared_ptr to the object must exist before you can call shared_from_this.
这篇关于提高shared_from_this&LT;&GT;()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!