单例模式
在这里插入代码片
#include<iostream>
using namespace std;
class Signal{
private:
Signal(){cout<<"构造函数调用"<<endl;}
Signal(const Signal &){}
static Signal* instance;
public:
static Signal* getInstance(){
//if(0 == instance){
// instance = new Signal();
//}
return instance;
}
};
Signal* Signal::instance = new Signal(); //懒汉模式
//Signal* Signal::instance = 0; //饿汉模式
int main(){
Signal* s1 = Signal::getInstance();
Signal* s2 = Signal::getInstance();
Signal* s3 = Signal::getInstance();
return 0;
}