//C++单例模式:指一个类只生成一个对象
#include <iostream>
using namespace std;
class A{
public:
static A* getA();
static A* a;
int b = 0;
void funAdd(){
b++;
cout<<b<<"\n";
};
void funClear(){
b = 0;
}
};
A *A::a = NULL;
A *A::getA()
{
if (a == NULL) {
a = new A;
}
return a;
}
int main(int argc, const char * argv[])
{
for (int i=0; i<10; i++) {
(A::getA())->funAdd();
if (i == 4) {
(A::getA())->funClear();
}
}
return 0;
}