单件模式-- 5种创建型模式之一

保证一个类只有一个实例

# include <iostream>

class Singleton {
public:
        static Singleton *GetSingleton() {
                static Singleton obj;
                return &obj;
        }
private:
        Singleton() {}
};

int main()
{
        Singleton *obj = Singleton::GetSingleton();

        return 0;
}

  

posted @ 2017-09-05 17:47  宁静淡泊  阅读(113)  评论(0)    收藏  举报