Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify safety of std::unique_ptr #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/en-us/05-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::cout << "pointer3.use_count() = "

## 5.3 `std::unique_ptr`

`std::unique_ptr` is an exclusive smart pointer that prohibits other smart pointers from sharing the same object, thus keeping the code safe:
`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:

```cpp
std::unique_ptr<int> pointer = std::make_unique<int>(10); // make_unique, from C++14
Expand Down
2 changes: 1 addition & 1 deletion book/zh-cn/05-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::cout << "pointer3.use_count() = "

## 5.3 `std::unique_ptr`

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

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