码迷,mamicode.com
首页 > 其他好文 > 详细

单例模式

时间:2016-08-19 16:20:07      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

class Singleton  
{
    public:
        static Singleton& Instance()
    {
        static Singleton instance;
        return instance;
    }
    private:
        Singleton();
        ~Singleton();
        Singleton(const Singleton&);
        Singleton& operator=(const Singleton&);
};

 采用effective c++中的方法,这里用到了static Singleton instance;这是一个local static对象,只有在第一次访问Instance()对象时候才会创建。注意这边将构造和析构函数都设为私有并且只声明,因此编译器不会在需要的时候自动再产生。

via(http://www.zkt.name/dan-li-mo-shi-singleton-ji-c-shi-xian/) 

单例模式

标签:

原文地址:http://www.cnblogs.com/rockwall/p/5788020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!