Comments (3)
事实上 std::unique_ptr 只能 "一定程度上的" 帮助用户防止内存泄漏, 而 不能保证代码安全
, 甚至会在某些情况引入额外的灾难.
首先, C++ 本身无法禁止用户使用同一个指针构造多个智能指针(甚至可以是不同类型的智能指针),
其次, 即使使用 std::make_unique/ std::make_shared 委托构造, 也不能杜绝用户利用该智能指针实际指向的地址再次构造新的智能指针.
所以说粗略的把 "智能指针" 和 "安全" 混为一谈是一种不现实的痴心妄想, 用户不该认为, 或者误导他人可能有这样的 "安全"
.
from modern-cpp-tutorial.
大佬 fork 一个单独的版本吧
from modern-cpp-tutorial.
Thanks and PR welcome
from modern-cpp-tutorial.
Related Issues (20)
- 第6章的习题设置不合理 HOT 1
- 网页端渲染存在问题 HOT 1
- 关于普通重载和override的一个区别 HOT 1
- 第二章 尾返回类型推导 “我们已经提过 auto 不能用于函数形参进行类型推导” HOT 2
- Chapter 2 exercise answer bug HOT 2
- 第八章内容 HOT 1
- 网页加载速度 HOT 1
- P43 || 43页 HOT 1
- C++ 中不允许将 `NULL` 定义为 `((void*)0)` HOT 2
- `3.3` 右值引用中的错误描述 HOT 1
- lambda 表达式隐式捕获用“编译器自行推导”这种措辞极度不合适 HOT 24
- 多线程中不该牵扯 `volatile` 关键字,且描述经不起推敲没有逻辑,带有错误暗示
- RAII 不是一种语法,第七章描述错误 HOT 1
- 描述 `std::mutex` 的用词奇怪,应当更改 HOT 3
- “堆栈回退”我认为您要表达的是:“栈回溯” HOT 1
- 2.3 中的 `typeof` 不是 C++ 中的标准特性 HOT 1
- `constexpr` 一节中,是编译器扩展导致,而非是新编译器优化的问题,解释有误 HOT 1
- 2.6章节-显式虚虚函数重载-final禁止子类重载 的示例容易产生误解 HOT 2
- 第四章 `std::tuple` 的遍历的内容有些过时与复杂 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modern-cpp-tutorial.