#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;

}

C++ 单例模式实现及代码解析

原文地址: https://www.cveoy.top/t/topic/qwsa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录