#include <iostream>
using namespace std;
class CSingleton
{
//其他成员
public:
static CSingleton* GetInstance();
int age;
private:
CSingleton(){};
static CSingleton* m_pInstance;
};
CSingleton* CSingleton::GetInstance()
{
if ( m_pInstance == NULL ) //判断是否第一次调用
m_pInstance = new CSingleton();
return m_pInstance;
}
int main()
{
CSingleton* p1 = CSingleton::GetInstance();
p1->age=10;
cout<<p1->age;
return 0;
}