1. 说明
匿名函数对象,不用在一个类中去定义了。
2. 形式
[](){}
- 中括号内是捕获的值,默认传值引用,加上
&
可以传引用 - 小括号里就是函数的参数。
- 大括号内是函数内容
3. 举例
struct S2 { void f(int i); };
void S2::f(int i)
{
[&] {}; // OK: by-reference capture default
[&, i] {}; // OK: by-reference capture, except i is captured by copy
[&, this] {}; // OK, equivalent to [&]
[&, this, i] {}; // OK, equivalent to [&, i]
}