//单例设计模式
class Solution {
public:
/**
* @return: The same instance of this class every time
*/
static Solution* getInstance() {
// write your code here
if(pInstance == NULL){
pInstance = new Solution();
}
return pInstance;
}
private:
//静态成员不会因为多个对象的存在而存在多份
static Solution*pInstance;
};
//初始化
Solution* Solution::pInstance = NULL;
LintCode:单例204
最新推荐文章于 2021-02-09 03:59:14 发布