Skip to content

Commit a548ea7

Browse files
jyj407changkun
authored andcommitted
Print out the stored_value1 and stored_value2 for the lambda example. (changkun#36)
* Fix compilation error for structured binding The header <tuple> is missing. After adding it, it compiles fine with clang in c++17 mode. * Print out the stored_value1 and stored_value2 for the lambda example. To make it eaiser for the readers to understand the difference between lambda capture by value and by reference.
1 parent e80a712 commit a548ea7

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

code/3/3.1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void learn_lambda_func_1() {
1616
};
1717
value_1 = 100;
1818
auto stored_value_1 = copy_value_1();
19+
std::cout << "stored_value_1=" << stored_value_1 << std::endl;
1920
// 这时, stored_value_1 == 1, 而 value_1 == 100.
2021
// 因为 copy_value_1 在创建时就保存了一份 value_1 的拷贝
2122
}
@@ -27,6 +28,7 @@ void learn_lambda_func_2() {
2728
};
2829
value_2 = 100;
2930
auto stored_value_2 = copy_value_2();
31+
std::cout << "stored_value_2=" << stored_value_2 << std::endl;
3032
// 这时, stored_value_2 == 100, value_1 == 100.
3133
// 因为 copy_value_2 保存的是引用
3234
}

0 commit comments

Comments
 (0)