class CSingleton
{
public:
static CSingleton* getInstance()
{
if (NULL == ps)
{//tag1
ps = new CSingleton;
}
return ps;
}
private:
CSingleton(){}
CSingleton & operator=(const CSingleton &s);
static CSingleton* ps;
};
CSingleton* CSingleton::ps = NULL;
static CSingleton* getInstance()
{
lock();//伪代码
if (NULL == ps)
{
ps = new CSingleton;
}
return ps;
}
CSingleton::instance()->aaaa(); CSingleton::instance()->bbbb(); CSingleton::instance()->cccc();
static CSingleton* getInstance()
{
if (NULL == ps)//这里加了次判断,只有第一次才会为true而调用lock()
{
lock();//伪代码
if (NULL == ps)
{
ps = new CSingleton;
}
}
return ps;
}
static CSingleton* getInstance()
{
if (NULL == ps)
{
lock();//伪代码
if (NULL == ps)
{ //伪代码
ps = xx;//step 3
new sizeof(CSingleton);//step 1
new CSingleton;//step 2
}
}
return ps;
}
CSingleton::getInstance()->aa(); CSingleton::getInstance()->bb(); CSingleton::getInstance()->cc();
CSingleton* const g_ps = CSingleton::getInstance();//程序一开始就缓存这个单例对象 g_ps->aa(); g_ps->bb(); g_ps->cc();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有