[=]
Lambda 可以使用语法从创建成员的上下文中捕获成员。我假设必须有一个状态引用存储在 lambda 中,类似于this
指针。
class Class
{
public:
void Function()
{
/*
* pass this lambda expression as parameter to another
* function and from there recover the this pointer which
* would be of the type Class* for further usage.
*/
[=](int)->int { /* do something with this->Member */ }
}
private:
int Member;
};
有没有办法从 lambda 表达式中获取引用指针?