日志
单模
2012-06-04 23:29
对于资源管理和特殊的对象管理,这个模式很有效
#ifndef TEST_H #define TEST_H #include <iostream> using namespace std; class Test { public: static Test* getTestClass(); ~Test(){cout<<"~~";} void setI(int a) {i = a;} int getI() const {return i;} private: Test(); int i; }; #endif // TEST_H #include "test.h" Test::Test() { } Test* Test::getTestClass() { static Test t; return &t; } |