0
我使用boost调度器(io_service)异步执行“methodB”。在这个方法中,我想保留一个指向B类实例的指针,所以我使用shared_ptr。但在下面的例子中,我想知道在“methodA”范围之后,指针仍然可以访问到“methodB”中,或者指针refcounter将等于零。在boost调度器中访问shared_ptr
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 ???
}
非常感谢。