谈谈C++中的单例

qq_33079 4 0 PDF 2021-01-16 22:01:56

写C++的时候用到单例,于是很自然的写出如下的代码: namespace tlanyan { class Foo { private: static Foo* _instance; Foo() {} // other members public: static Foo* getInstance() { if (_instance == NULL) { _instance = new Foo(); } return _instance; } ~Foo() { // cl

用户评论
请输入评论内容
评分:
暂无评论