CPlusPlusThings/learn_class/modern_cpp_30/memorymodel_atomic/iazysingleton.cpp

20 lines
293 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;
}