令我感到羞耻的是,我没有机会在实际开发中使用智能指针(主管认为它太“复杂”并且浪费时间)。但是,我计划将它们用于我自己的东西......
我遇到了关于在模块完成后或在加载新数据时取消初始化模块的情况。当我使用指针时,我发现我的代码中到处都是检查 null ,例如这样......
// TODO: Reset all opened windows
// Deinit track result player
if (trackResultPlayer_)
trackResultPlayer_->reset();
// disconnect track result player
disconnect(trackResultPlayer_);
disconnect(trackResultAnimator_);
}
if (videoPlayerWindow_)
{
videoPlayerWindow_->reset();
// Disconnect the video player window from source movie data
disconnect(videoPlayerWindow_);
}
// Disconnect this module from its children as they would be connected again
disconnect(this);
如果我要使用智能指针而不是原始指针,如何缓解这个问题?