当前位置:编程学习 > C/C++ >>

C++单例模型的例子

#include <iostream> 
#include <new> 
using namespace std; 
 
class CGlobalInstance 

  private: 
       CGlobalInstance(); 
       virtual ~CGlobalInstance(); 
       static CGlobalInstance* m_this; 
  public:   
   static CGlobalInstance* get_instance(); 
   void out(); 
}; 
 
 
CGlobalInstance::CGlobalInstance() 

 

 
 
CGlobalInstance::~CGlobalInstance() 

 

 
void CGlobalInstance::out() 

    cout<<"hi man"<<endl; 

 
CGlobalInstance* CGlobalInstance::get_instance() 

   if (NULL == m_this) 
   { 
     m_this = new CGlobalInstance(); 
   } 
   return m_this; 

 
CGlobalInstance* CGlobalInstance::m_this = NULL; 
 
int main(void) 

  CGlobalInstance::get_instance()->out(); 


摘自 工作记录--创造或收集原创
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,