设计模式之单例模式
class Singelton
{
public:
static Singelton *getInstance()
{
if(m_p == NULL)
{
m_p = new Singelton;
}
return m_p;
}
static void destroyInstance()
{
delete m_p;
m_p = NULL;
}
private:
Singelton() {}
static Singelton *m_p;
};
Singelton *Singelton::m_p = NULL;
int main()
{
Singelton *p1;
p1 = Singelton::getInstance();
Singelton *p2;
p2 = Singelton::getInstance();
cout << p1 << "," << p2 << endl;
P1 = P2 = NULL;
}