C – 什么时候非指针类成员被破坏?
发布时间:2020-12-16 10:38:46 所属栏目:百科 来源:网络整理
导读:假设我有这个代码…… class GraphFactory : public QObject{private: QMapQString,IGraphCreator* factory_;public: virtual ~GraphFactory();};GraphFactory::~GraphFactory(){ // Free up the graph creators QMapQString,IGraphCreator*::iterator itr;
假设我有这个代码……
class GraphFactory : public QObject { private: QMap<QString,IGraphCreator*> factory_; public: virtual ~GraphFactory(); }; GraphFactory::~GraphFactory() { // Free up the graph creators QMap<QString,IGraphCreator*>::iterator itr; for (itr = factory_.begin(); itr != factory_.end(); itr++) { IGraphCreator * creator = itr.value(); delete creator; creator = NULL; } } QMap工厂何时被销毁?在调用析构函数之前,还是在析构函数期间? (我知道当GraphFactory的一个实例超出范围时会调用析构函数.但是什么时候非指针成员被销毁?) 编辑:当到达析构函数时,我得到了factory_ map的无效值.断点显示该值不会篡改QMap中存储的值. 解决方法
它将在析构函数代码执行后被破坏
我们的想法是在析构函数代码中访问您的成员,以便它们在执行后被销毁. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |