面试中遇到了一个手写单例模式的题,在这里总结一下:

 

class CSingleton
{
public:
    static CSingleton* getInstance()
    {
        if (NULL == instance) {
            instance = new CSingleton();
        }
        return instance;
    }

private:
    CSingleton(){}
    virtual ~CSingleton(){}
    static CSingleton* instance;
};