Skip to content

Commit 6f5615b

Browse files
committed
book: fix an inconsistency between en-us and zh-cn
1 parent e202554 commit 6f5615b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

book/en-us/03-runtime.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ The type of the captured variable being declared is judged according to the expr
105105
and the judgment is the same as using `auto`:
106106

107107
```cpp
108-
#include <memory>
108+
#include <iostream>
109+
#include <memory> // std::make_unique
110+
#include <utility> // std::move
109111

110112
void lambda_expression_capture() {
111113
auto important = std::make_unique<int>(1);

book/zh-cn/03-runtime.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void lambda_reference_capture() {
6767
}
6868
```
6969

70-
**3. 隐式捕获**
70+
#### 3. 隐式捕获
7171

7272
手动书写捕获列表有时候是非常复杂的,这种机械性的工作可以交给编译器来处理,这时候可以在捕获列表中写一个
7373
`&``=` 向编译器声明采用引用捕获或者值捕获.
@@ -79,7 +79,7 @@ void lambda_reference_capture() {
7979
- \[&\] 引用捕获, 让编译器自行推导引用列表
8080
- \[=\] 值捕获, 让编译器自行推导值捕获列表
8181

82-
**4. 表达式捕获**
82+
#### 4. 表达式捕获
8383

8484
> 这部分内容需要了解后面马上要提到的右值引用以及智能指针
8585
@@ -93,13 +93,12 @@ C++14 给与了我们方便,允许捕获的成员用任意的表达式进行
9393
#include <memory> // std::make_unique
9494
#include <utility> // std::move
9595

96-
int main() {
96+
void lambda_expression_capture() {
9797
auto important = std::make_unique<int>(1);
9898
auto add = [v1 = 1, v2 = std::move(important)](int x, int y) -> int {
9999
return x+y+v1+(*v2);
100100
};
101101
std::cout << add(3,4) << std::endl;
102-
return 0;
103102
}
104103
```
105104

0 commit comments

Comments
 (0)