CPlusPlusThings/design_pattern/singleton/iazysingleton.cpp

21 lines
280 B
C++

//
// Created by light on 20-2-6.
//
class singleton {
private:
singleton() {}
static singleton *p;
public:
static singleton *instance();
};
singleton *singleton::p = nullptr;
singleton *singleton::instance() {
if (p == nullptr)
p = new singleton();
return p;
}