文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c++ single instance

c++ single instance

时间:2010-03-18  来源:@sky

#include <iostream>

using namespace std;

class Temp {
        public:
                Temp()  { cout << "constructor" << endl; }
                ~Temp() { cout << "destructor" << endl;  }

                static Temp * getInstance();
                static void putInstance();
        private:
                static Temp *instance;
};

Temp * Temp::getInstance()
{
        cout << "getInstance" << endl;
        if (!instance)
                instance = new Temp();

        return instance;
}

void Temp::putInstance()
{
        cout << "putInstance" << endl;
        if (instance) {
                delete instance;
                instance = NULL;
        }
}

Temp * Temp::instance = NULL;

int main()
{
        Temp *p;        /* don't invoke constructor */

        p = Temp::getInstance();

        Temp::putInstance();

        return 0;
}

相关阅读 更多 +
排行榜 更多 +
神殿ios版官网入口

神殿ios版官网入口

角色扮演 下载
邻居不对劲汉化移植版下载

邻居不对劲汉化移植版下载

冒险解谜 下载
神殿娱乐onliNe官网版

神殿娱乐onliNe官网版

模拟经营 下载