C++ 单例模式实现及代码解析
#include
class Single{ public: static Single* getInstance(){ if(instance == NULL){ instance = new Single();
}
return instance;
}
void destroyInstance(){
if(instance != NULL){
delete instance;
instance = NULL;
}
}
private:
Single(){
}
~Single(){
}
Single(const Single &o){
}
static Single *instance;
}; Single* Single::instance =NULL; int main(){ Single *p = Single::getInstance(); p = Single::getInstance(); p->destroyInstance(); return 0;
}
原文地址: https://www.cveoy.top/t/topic/qwsa 著作权归作者所有。请勿转载和采集!