Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions book/03-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Lambda 表达式的基本语法如下:
void learn_lambda_func_1() {
int value_1 = 1;
auto copy_value_1 = [value_1] {
return value_1;
};
value_1 = 100;
auto stored_value_1 = copy_value_1();
return value_1;
};
value_1 = 100;
auto stored_value_1 = copy_value_1();
// 这时, stored_value_1 == 1, 而 value_1 == 100.
// 因为 copy_value_1 在创建时就保存了一份 value_1 的拷贝
}
Expand All @@ -66,10 +66,10 @@ auto stored_value_1 = copy_value_1();
void learn_lambda_func_2() {
int value_2 = 1;
auto copy_value_2 = [&value_2] {
return value_2;
};
value_2 = 100;
auto stored_value_2 = copy_value_2();
return value_2;
};
value_2 = 100;
auto stored_value_2 = copy_value_2();
// 这时, stored_value_2 == 100, value_1 == 100.
// 因为 copy_value_2 保存的是引用
}
Expand Down Expand Up @@ -137,7 +137,7 @@ Lambda 表达式的本质是一个函数对象,当 Lambda 表达式的捕获
#include <iostream>

using foo = void(int); // 定义函数指针, using 的使用见上一节中的别名语法
void functional(foo f) {
void functional(foo f) {
f(1);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ int main() {

int important = 10;
std::function<int(int)> func2 = [&](int value) -> int {
return 1+value+important;
return 1+value+important;
};
std::cout << func(10) << std::endl;
std::cout << func2(10) << std::endl;
Expand Down Expand Up @@ -216,7 +216,7 @@ int main() {

```cpp
std::vector<int> foo() {
std::vector<int> temp = {1, 2, 3, 4};
std::vector<int> temp = {1, 2, 3, 4};
return temp;
}

Expand Down Expand Up @@ -439,4 +439,4 @@ std::forward 传参:左值引用

<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png" /></a>

本教程由[欧长坤](https://github.com/changkun)撰写,采用[知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议](http://creativecommons.org/licenses/by-nc-nd/4.0/)许可。项目中代码使用 MIT 协议开源,参见[许可](../LICENSE)。
本教程由[欧长坤](https://github.com/changkun)撰写,采用[知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议](http://creativecommons.org/licenses/by-nc-nd/4.0/)许可。项目中代码使用 MIT 协议开源,参见[许可](../LICENSE)。