草庐IT

c++ - 如果我碰巧注意到它已过期,我应该在 weak_ptr 上调用 reset 吗?

我收藏了Creature使用std::make_shared在我的应用程序的一部分中创建和拥有的对象和std::shared_ptr.我还跟踪了零个或一个的选择Creature在World使用std::weak_ptr的对象.voidWorld::SetSelection(conststd::shared_ptr&creature){selection=creature;}std::shared_ptrWorld::GetSelection()const{returnselection.lock();}GetSelection的来电者负责检查指针是否为空。如果是,则表示当前没有选择。T