Skip to content

Commit d2c08cc

Browse files
Clarify safety of unique_ptr
1 parent 01b64d4 commit d2c08cc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

book/en-us/05-pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ std::cout << "pointer3.use_count() = "
8282

8383
## 5.3 `std::unique_ptr`
8484

85-
`std::unique_ptr` is an exclusive smart pointer that prohibits other smart pointers from sharing the same object, thus keeping the code safe:
85+
`std::unique_ptr` is an exclusive smart pointer that prohibits other smart pointers from sharing the same object by copy construction or copy assignment, thus avoiding errors due to repeated destruction or freeing:
8686

8787
```cpp
8888
std::unique_ptr<int> pointer = std::make_unique<int>(10); // make_unique, from C++14

book/zh-cn/05-pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::cout << "pointer3.use_count() = "
8080

8181
## 5.3 `std::unique_ptr`
8282

83-
`std::unique_ptr` 是一种独占的智能指针,它禁止其他智能指针与其共享同一个对象,从而保证代码的安全
83+
`std::unique_ptr` 是一种独占的智能指针,它禁止其他智能指针经由拷贝构造或拷贝赋值的方式与其共享同一个对象,从而避免重复析构或释放带来的错误
8484

8585
```cpp
8686
std::unique_ptr<int> pointer = std::make_unique<int>(10); // make_unique 从 C++14 引入

0 commit comments

Comments
 (0)