LintCode:单例204

//单例设计模式
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算法)