C++ 实现单例

单例(Singleton),即一个类只有一个实例。

私有构造函数

1
2
3
4
5
6
7
8
9
10
11
12
13
class Singleton
{
private:
    Singleton() { };
    ~Singleton() { };
    Singleton(const Singleton&);
    Singleton& operator=(const Singleton&);
public:
    static Singleton& getInstance() {
        static Singleton instance;
        return instance;
    }
};

 

posted @   happyyoung  阅读(5339)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示