单例模式在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();
最后
以上就是忧心羽毛最近收集整理的关于单例模式与懒加载方式。的全部内容,更多相关单例模式与懒加载方式内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复