单例模式(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() { }