CPlusPlusThings/design_pattern/singleton/hungrysingleton.cpp

16 lines
240 B
C++

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