c++单例模式

自己写的单例模式

class singleton{
public:
    
    singleton(const singleton&) = delete;
    singleton& operator=(const singleton& rhs) = delete;
    static singleton* getinstance(){
        if (ptr == NULL) {
            ptr = new singleton(); return ptr;
        }
        else return NULL;
    }
    int geta(){ return a; }
private:
    static singleton* ptr;
    singleton(){ a = 5; }
    int a;
};
Singleton* Singleton::ptr = NULL;

 

posted @ 2017-10-15 22:46  hchacha  阅读(244)  评论(0)    收藏  举报