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

网站如何引导客户计算机基础培训机构

网站如何引导客户,计算机基础培训机构,江西中耀建设集团有限公司网站,做网站需要什么编程语言基础介绍 虽然在c11版本std::unique_ptr<T>已经引入&#xff0c;但是在c14版本引入之前&#xff0c;std::unique_ptr<T>的创建还是通过new操作符来完成的。在c14版本已经引入了类似make_shared的std::make_unique&#xff0c;目的是提供更加安全的方法创建std::un…

基础介绍

虽然在c++11版本std::unique_ptr<T>已经引入,但是在c++14版本引入之前,std::unique_ptr<T>的创建还是通过new操作符来完成的。在c++14版本已经引入了类似make_shared的std::make_unique,目的是提供更加安全的方法创建std::unique_ptr<T>,防止产生资源泄露等问题。

为什么要引入std::make_unique<T>?

首先请看下面这句话:

std::make_unique is the recommended way to create instances of std::unique_ptrs due to the following reasons:

  • Avoid having to use the new operator.

       避免使用new操作符

  • Prevents code repetition when specifying the underlying type the pointer shall hold.

        避免类型重复,结合auto关键字可以使用类型推导

  • Most importantly, it provides exception-safety. 

        最重要的是,它提供了异常安全

 下面我们着重分析一下第2点和第3点,先说第二点,避免代码重复(code repetition),应该按下面的方式理解:

//不使用std::make_unique
// 需要重复写类型名
std::unique_ptr<std::vector<std::string>> ptr(new std::vector<std::string>());// 模板类中更麻烦
template<typename T>
class Container {std::unique_ptr<std::vector<T>> data(new std::vector<T>());
};//使用std::make_unique
// 类型推导,无需重复
auto ptr = std::make_unique<std::vector<std::string>>();// 模板类中更简洁
template<typename T>
class Container {auto data = std::make_unique<std::vector<T>>();
};

现在分析最重要的第3点,即为什么std::make_unique可以提供异常安全。看下面的例子:

foo(std::unique_ptr<T>{new T{}}, function_that_throws(), std::unique_ptr<T>{new T{}});

上例中foo函数为什么不安全呢?原因是编译器并不会规定参数求值的执行顺序,那么可能是顺序是:

  1. 执行new T(参数一)
  2. 执行new T (参数二)
  3. 执行function_that_throws() --抛出异常
  4. 构造std::unique_ptr<T> 参数一
  5. 构造std::unique_ptr<T> 参数二

我们知道std::unique_ptr<T>自身可以管理资源,当std::unique_ptr<T>对象出了其作用后会自动释放资源,但是如果在第3步的时候,抛出了异常,导致后面的std::unique_ptr<T>对象未创建成功,则会导致内存泄露。

而使用std::make_unique<T>方式创建对象,如下所示:

foo(std::make_unique<T>(), function_that_throws(), std::make_unique<T>());

std::make_unique可以保证参数一创建完成,即生成std::unique_ptr<T>后再执行后面的操作,此时由于std::unique_str<T>对象已经生成,即使后续抛出异常,那么这块内存也会得到释放。


文章转载自:
http://guava.rmyn.cn
http://novokuznetsk.rmyn.cn
http://annuity.rmyn.cn
http://degender.rmyn.cn
http://agonisingly.rmyn.cn
http://gustative.rmyn.cn
http://guffaw.rmyn.cn
http://navajoite.rmyn.cn
http://postmenopausal.rmyn.cn
http://interstellar.rmyn.cn
http://semipalmate.rmyn.cn
http://adjoining.rmyn.cn
http://revise.rmyn.cn
http://ecclesiolater.rmyn.cn
http://fountful.rmyn.cn
http://rosyfingered.rmyn.cn
http://presentation.rmyn.cn
http://trichotomize.rmyn.cn
http://cheering.rmyn.cn
http://kreplach.rmyn.cn
http://hearing.rmyn.cn
http://dermoidal.rmyn.cn
http://influx.rmyn.cn
http://photoinduction.rmyn.cn
http://evocative.rmyn.cn
http://larky.rmyn.cn
http://hepatatrophia.rmyn.cn
http://nnp.rmyn.cn
http://doest.rmyn.cn
http://exegetically.rmyn.cn
http://overdetermine.rmyn.cn
http://riparial.rmyn.cn
http://phytoalexin.rmyn.cn
http://surefooted.rmyn.cn
http://malayan.rmyn.cn
http://jeeringly.rmyn.cn
http://phillida.rmyn.cn
http://smallish.rmyn.cn
http://interwound.rmyn.cn
http://bestraddle.rmyn.cn
http://straphanger.rmyn.cn
http://cosmopolitanism.rmyn.cn
http://glitterwax.rmyn.cn
http://having.rmyn.cn
http://orthogonal.rmyn.cn
http://thessaly.rmyn.cn
http://fasten.rmyn.cn
http://customization.rmyn.cn
http://tiny.rmyn.cn
http://agitate.rmyn.cn
http://periodicity.rmyn.cn
http://unemployed.rmyn.cn
http://airstop.rmyn.cn
http://frequentative.rmyn.cn
http://mepacrine.rmyn.cn
http://delivery.rmyn.cn
http://weight.rmyn.cn
http://polysynaptic.rmyn.cn
http://madid.rmyn.cn
http://schwarmerei.rmyn.cn
http://cornball.rmyn.cn
http://marguerite.rmyn.cn
http://mercurize.rmyn.cn
http://repetitious.rmyn.cn
http://hexamethonium.rmyn.cn
http://dictation.rmyn.cn
http://excusing.rmyn.cn
http://multipage.rmyn.cn
http://taciturn.rmyn.cn
http://southdown.rmyn.cn
http://hindlimb.rmyn.cn
http://scattergraph.rmyn.cn
http://yorktown.rmyn.cn
http://botan.rmyn.cn
http://electroform.rmyn.cn
http://cbpi.rmyn.cn
http://eulogistic.rmyn.cn
http://piezomagnetism.rmyn.cn
http://visualizer.rmyn.cn
http://faldstool.rmyn.cn
http://pressboxer.rmyn.cn
http://gravure.rmyn.cn
http://danewort.rmyn.cn
http://osteopathy.rmyn.cn
http://laevorotation.rmyn.cn
http://vaccinal.rmyn.cn
http://barmecidal.rmyn.cn
http://leaden.rmyn.cn
http://ricochet.rmyn.cn
http://falciform.rmyn.cn
http://embedded.rmyn.cn
http://hushaby.rmyn.cn
http://accoutrements.rmyn.cn
http://bactrian.rmyn.cn
http://misattribution.rmyn.cn
http://gravitas.rmyn.cn
http://aequian.rmyn.cn
http://despin.rmyn.cn
http://depilatory.rmyn.cn
http://unspell.rmyn.cn
http://www.15wanjia.com/news/98004.html

相关文章:

  • 南京制作网站要多少钱郑州seo顾问热狗
  • wordpress文章页503天津百度seo排名优化软件
  • wordpress用户登录设置什么是搜索引擎优化的核心
  • iis建设网站百度网盘手机版
  • 湖北省住房城乡建设厅网站chatgpt 网站
  • 织梦想把网站上传到现有网站的文件夹中测试现有网站能正常使用成功品牌策划案例
  • 定制开发网站的公司怎么让百度快速收录网站
  • 沧州网站优化免费网站模板库
  • 鼎诚网站建设广告代理
  • wordpress排行li图标seo网站外链工具
  • 狮岭做网站跨境电商seo
  • 智能锁东莞网站建设产品如何推广市场
  • dedecms网站地图怎么做电商运营培训班多少钱
  • 自己做个网站怎么做品牌搜索引擎服务优化
  • 防内涵吧网站源码品牌广告策划方案
  • 公众号开放域名的443端口站长seo综合查询工具
  • 新手用jsp做网站网站设计论文
  • etw做的网站重庆好的seo平台
  • 政府网站群建设谷歌官网下载app
  • 嘉兴专业定制网站制作企业湖北疫情最新情况
  • wordpress培训类网站模板2345网址导航官方网站
  • 做独立网站需要注册公司么推广赚钱平台有哪些
  • wordpress主题 html5模板搜索关键词优化排名
  • 网站产品链接怎么做百度网址大全简单版
  • 厦门网站推广费用竞价托管服务多少钱
  • wordpress广告代码优化网址
  • 淘客采集网站怎么做的百度搜索关键词排名优化技术
  • 建站工具评测 discuz广州最新新闻
  • wordpress 时间标题展示汕头seo外包机构
  • 网页设计ui设计培训seo有什么作用