概述
单例模式在C++类的设计模式中很普遍。
定义
#define ImplementInstance(cls)
public:
static cls* cls::GetInstance()
{
static cls* m_pInstance = NULL;
if (!m_pInstance)
{
m_pInstance = new_nothrow cls;
}
return m_pInstance;
}
调用
class COneInstance
{
public:
COneInstance(){};
~COneInstance(){};
ImplementInstance(COneInstance)
public:
void calcuteNum(){};
}
COneInstance::GetInstance()->calcuteNum();
最后
以上就是忧心羽毛为你收集整理的单例模式与懒加载方式。的全部内容,希望文章能够帮你解决单例模式与懒加载方式。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复