题目:
设计一个类,我们只能生成该类的一个实例
解法:
class Test {
private:
static Test* instance;
Test() {
}
public:
Test* getInstance() {
if (instance == 0) {
instance = new Test();
}
return instance;
}
};
Test* Test::instance = 0;
网友评论