1.单例模式:一个类不管创建多少对象,永远只能得到该类型一个对象的实例
常用:日志模块,数据库模块
//饿汉:
class singleton
{
public:
//用户可以通过该接口调用静态对象
static singleton* getInstance(){
//#3获取类的唯一实例对象的接口方法
return &instance;
}
private:
static singleton instance; //#2定义一个唯一的类的实例对象
singleton(){
}//#1构造函数私有化
singleton(const singleton&)=delete;
singleton& operator=(const singleton&)=delete;
}