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 ???
}
非常感謝。