文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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;
}

相关阅读 更多 +
排行榜 更多 +
jojo的奇妙冒险手机版下载

jojo的奇妙冒险手机版下载

飞行射击 下载
雪糕工厂 v9.87.13.02 安卓版

雪糕工厂 v9.87.13.02 安卓版

休闲益智 下载
雪糕工厂 v9.87.13.02 安卓版

雪糕工厂 v9.87.13.02 安卓版

休闲益智 下载