备忘 ^_^

.h 文件

Class OneWnd

{

private:

 

OneWnd(void);

~OneWnd(void);
static OneWnd* m_pInstance;

class CGarbo
    { 
    public: 
         ~CGarbo() 
         { 
             if (OneWnd::Instance())
             {
                 // to do clear something…

             }
         } 
    }; 
   
     static CGarbo Garbo;

 

public:

static OneWnd* Instance();

}

 

.cpp文件


OneWnd* OneWnd::m_pInstance = NULL;

OneWnd* OneWnd::Instance()
{
    if (m_pInstance == NULL )
    {
        m_pInstance = new OneWnd();
    }

    return m_pInstance;
}

 

以后不能忘了哈~~~

 

 

注:(2010-10-21)

Instance()方法里的 m_pInstance 这个值不能写成this->m_pInstance 会报错的哦

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-11-07
  • 2021-10-28
  • 2022-02-27
  • 2022-12-23
猜你喜欢
  • 2021-05-30
  • 2021-08-26
  • 2021-10-29
  • 2022-12-23
  • 2021-09-13
  • 2021-12-15
  • 2021-08-01
相关资源
相似解决方案