剑指offer 面试题2:实现Singleton模式
2016-06-20 本文已影响0人
qmss
题目:
设计一个类,我们只能生成该类的一个实例
解法:
class Test {
private:
static Test* instance;
Test() {
}
public:
Test* getInstance() {
if (instance == 0) {
instance = new Test();
}
return instance;
}
};
Test* Test::instance = 0;