当前位置: 首页 > news >正文

网络运维工程师面试常见问题seo关键词排名优化联系方式

网络运维工程师面试常见问题,seo关键词排名优化联系方式,怎样用自己的电脑,做网站,苏州网站设计公司有哪些返回管理this的shared_ptr 通过wek_ptr返回管理this资源的共享智能指针对象shared_ptr。C11中为我们提供了一个模板类叫做std::enable_shared_from_this,这个类中有一个方法叫做shared_from_this(),通过这个方法可以返回一个共享智能指针,在…

返回管理this的shared_ptr

通过wek_ptr返回管理this资源的共享智能指针对象shared_ptr。C++11中为我们提供了一个模板类叫做std::enable_shared_from_this,这个类中有一个方法叫做shared_from_this(),通过这个方法可以返回一个共享智能指针,在函数的内部就是使用weak_ptr来监测this对象,并通过调用weak_ptr的lock()方法返回一个shared_ptr对象。

#include <iostream>
#include <memory>
using namespace std;struct Test : public enable_shared_from_this<Test>
{shared_ptr<Test> getSharedPtr(){return shared_from_this();}~Test(){cout << "class Test is disstruct ..." << endl;}
};int main()
{shared_ptr<Test> sp1(new Test);cout << "use_count: " << sp1.use_count() << endl;shared_ptr<Test> sp2 = sp1->getSharedPtr();cout << "use_count: " << sp1.use_count() << endl;return 0;
}

循环引用的案例

#include <iostream>
#include <memory>
using namespace std;struct TA;
struct TB;struct TA
{shared_ptr<TB> bptr;~TA(){cout << "class TA is disstruct ..." << endl;}
};struct TB
{shared_ptr<TA> aptr;~TB(){cout << "class TB is disstruct ..." << endl;}
};void testPtr()
{shared_ptr<TA> ap(new TA);shared_ptr<TB> bp(new TB);cout << "TA object use_count: " << ap.use_count() << endl;cout << "TB object use_count: " << bp.use_count() << endl;ap->bptr = bp;bp->aptr = ap;cout << "TA object use_count: " << ap.use_count() << endl;cout << "TB object use_count: " << bp.use_count() << endl;
}int main()
{testPtr();return 0;
}

修改

#include <iostream>
#include <memory>
using namespace std;struct TA;
struct TB;struct TA
{weak_ptr<TB> bptr;~TA(){cout << "class TA is disstruct ..." << endl;}
};struct TB
{shared_ptr<TA> aptr;~TB(){cout << "class TB is disstruct ..." << endl;}
};void testPtr()
{shared_ptr<TA> ap(new TA);shared_ptr<TB> bp(new TB);cout << "TA object use_count: " << ap.use_count() << endl;cout << "TB object use_count: " << bp.use_count() << endl;ap->bptr = bp;bp->aptr = ap;cout << "TA object use_count: " << ap.use_count() << endl;cout << "TB object use_count: " << bp.use_count() << endl;
}int main()
{testPtr();return 0;
}
http://www.hkea.cn/news/648359/

相关文章:

  • 网站建设硬件设置竞价广告是怎么推广的
  • 网站的平面设计图用ps做国外搜索引擎大全百鸣
  • 深圳专业企业网站建设前端培训
  • 南京平台公司seo搜索培训
  • 横沥网站建设武汉百度百科
  • 百度给做网站公司线上运营的5个步骤
  • 盘锦网站建设公司网络营销策略包括哪些
  • 简述电子商务网站开发的基本原则一站式网络营销
  • 商丘网站网络推广员的工作内容和步骤
  • 取消wordpress邮箱认证北京搜索优化排名公司
  • 千库网素材南宁seo优势
  • 西安机场商务宾馆百度做网站怎么在百度上做网站
  • ps网站建设seo网络公司
  • 网站建设步骤 教 程网站怎么做谷歌推广
  • 网站制作需要注意什么潍坊做网站哪家好
  • 专门做团购的网站有哪些色盲图
  • 百度做网站续费费用百度营业执照怎么办理
  • 深圳网站建设方维网络企业网站制作要求
  • 制作好网站黑帽seo教程
  • 云南 网站建设网站seo优化对网店的推广的作用为
  • 网站建设免费国外舆情服务公司
  • 怎么做网站banner查排名网站
  • 做网站好看的背景图片相关搜索优化软件
  • 怎么查网站是哪家制作公司做的百度收录查询
  • 企业年金交了有好处吗网络优化工程师吃香吗
  • python做网站开发百度6大核心部门
  • 自己做网站平台企业网站优化价格
  • 淘宝网网站建设的需求分析百度会员登录入口
  • 建网站的专业公司推广网站多少钱
  • 网站不去公安局备案自己怎么搭建网站