C++14才有std::make_unique<T>(...)所以替换为std::unique_ptr<T>(new T(...))
原创 2022-06-13 13:53:34
825阅读
make_unique在c++11里面没有引入,但是你可以自己写一个 template <typename T, typename ...Args> std::unique_ptr<T> make_unique(Args&& ...args) { return unique_ptr<T>(new T ...
转载 2021-06-14 23:04:00
1053阅读
2评论
make_shared的使用:shared_ptr<string> p1 = make_shared<string>(10, '9'); shared_ptr<string> p2 = make_shared<string>("hello"); shared_ptr<
原创 2021-09-28 11:54:48
1517阅读
make_shared的使用: shared_ptr p1 = make_shared(10, '9'); shared_ptr p2 = make_share
转载 2021-01-04 19:52:00
647阅读
2评论
目录   引言 正文 引言 C++11标准库提供了两种智能指针,它们的区别在于管理底层指针的方式:shared_ptr允许多个指针指向同一个对象;unique_ptr则“独占”所指向的对象。C++11标准库还定义了一个名为weak_ptr的辅助类,它是一种弱引用,指向shared_ptr所管理的对象。这三种类型都定义在memory头文件中。智能指针是模板类而不是指针。类似vector,智能指针也
原创 2021-07-22 14:26:00
755阅读
记录 | C++ 用make_unique代替new
原创 2024-03-07 08:47:32
82阅读
R.23: Usemake_unique()to makeunique_ptrsR.23:使用make_unique构建unique_ptrReason(原因)For convenience a
翻译 2022-07-30 00:11:54
90阅读
C.150: Usemake_unique()to construct objects owned by u
翻译 2022-07-30 00:08:23
118阅读
使用make_unique获取一个智能指针,智能指针的类型是unique_ptr// a不是数组,小括号里
原创 2022-07-08 17:13:15
1485阅读
std::unique_ptrstd::unique_ptr是一种独占的语义,即只允许一个智能指针引用裸指针,这区别于std::shared_ptr允许多个shared_ptr引用同一个裸指针,它没有引用计数,它的性能比shared_ptr会高一点。
原创 2021-09-28 14:00:21
530阅读
如果computePriority()抛出异常,由于std::make_shared已经成功创建了std::shared_ptr,并且这个智能指针已经开始管理Widget对象,所除器,则必须直接使用new。
今天收到了 Windows Mobile 新闻邮件,发现微软出了一个新网站——Total Access,貌似与之前 Windows Mobile 里的频道类似主要是为提供用户更好体验、帮助及手机个性化的一个服务网站。我们可以访问:http://www.microsoft.com/windowsmobile/en-us/totalaccess/default.mspx Total Ac
原创 2009-03-09 18:16:00
984阅读
C++20 引入了两个新的标准库函数:std::make_shared_for_overwrite 和 std::make_unique_for_overwrite,它们为智能指针的使用带来了更高效、更安全的内存管理方式。本文将详细介绍这两个函数的用途、优势以及它们在实际开发中的应用场景。一、背景与动机在 C++ 中,std::shared_ptr 和 std::unique_ptr 是两种常用的
原创 6月前
64阅读
DescriptionGiven an array of integers A, a move consists of choosing any A[i], and incrementin
原创 2022-08-12 07:57:08
119阅读
A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of c ...
转载 2021-07-21 05:08:00
726阅读
2评论
DescriptionA string s is called good if there are no two different characters in s that have the same frequency.Given a string s, re
原创 2022-08-11 17:21:11
26阅读
作者: 负雪明烛id: fuxuemingzhu个人博客: http://fuxuemingzhu.cn/目录题目描述题目大意解题方法暴力求解,TLE一次遍历日期题目地址:https://leetcode.com/problems/minimum-increment-to-make-array-unique/description/题目描述Given an array of inte...
原创 2022-02-10 14:45:51
78阅读
作者: 负雪明烛id: fuxuemingzhu个人博客: http://fuxuemingzhu.cn/目录题目描述题目大意解题方法暴力求解,TLE一次遍历日期题目地址:https://leetcode.com/problems/minimum-increment-to-make-array-unique/description/题目描述Given an array of inte...
原创 2021-07-14 11:24:40
149阅读
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. Return the least number of moves to make every value in 
转载 2018-11-26 14:38:00
82阅读
2评论
用的哈希表加集合解决
原创 2023-05-27 00:03:11
40阅读
  • 1
  • 2
  • 3
  • 4
  • 5