单例模式(c++)

#include<iostream>

using namespace std;
//单例

class SingleTon {
public:
	static SingleTon* getinstance() {
		if (instance == nullptr)instance = new SingleTon;
		return instance;
	}

private:
	SingleTon(){}
	virtual ~SingleTon(){
		if(instance != nullptr)delete instance; instance = nullptr;
	}
	static SingleTon* instance;
};
//SingleTon* SingleTon::instance = new SingleTon;


int main() {

}

  

posted @ 2024-03-25 17:49  dmfsimle  阅读(0)  评论(0编辑  收藏  举报