【发布时间】:2014-02-05 20:42:48
【问题描述】:
我使用 boost 调度程序 (io_service) 异步执行“methodB”。在这个方法中,我想保留一个指向B类实例的指针,所以我使用了shared_ptr。但是在下面的例子中,我想知道在“methodA”的范围之后,指针是否仍然可以访问“methodB”,或者指针的 refcounter 是否会等于 0。
void ClassA::methodA(){
shared_ptr<ClassB> pointer(new ClassB);
m_dispatcher.post(boost::bind(&ClassA::methodB, this, pointer); // boost io_service
}
void ClassA::methodB(shared_ptr<ClassB> pointer){
ClassB *p = pointer.get(); // access to pointer ???
}
非常感谢。
【问题讨论】:
标签: boost boost-asio shared-ptr boost-thread dispatch