單模

             對於資源管理和特殊的對象管理,這個模式頗有效



 #ifndef TEST_Hios

#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;
}
相關文章
相關標籤/搜索