C++ 的 带捕获的lambda
等级 3130 次按键
[factor]把外部变量factor复制到lambda中,使其能在内部使用。multiply(5)返回15,multiply(10)返回30。
C++ 代码
// lambda外部的局部变量1int factor = 3;// [factor]按值捕获factor的副本;之后修改factor不会影响它2auto multiply = [factor](int x) { return x * factor; };// 5 * 3:输出153cout << multiply(5) << endl;// 10 * 3:输出304cout << multiply(10) << endl;运行结果
15 30
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C++ 代码中需要输入的符号及其出现次数。
<× 8;× 5(× 3)× 3=× 2[× 1]× 1{× 1}× 1*× 1