2019独角兽企业重金招聘Python工程师标准>>>
对于资源管理和特殊的对象管理,这个模式很有效
#ifndef 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;
}