C++ 是否=在lambda的捕获列表中捕获此指针
我现在有类似的东西C++ 是否=在lambda的捕获列表中捕获此指针,c++,c++11,lambda,C++,C++11,Lambda,我现在有类似的东西 void foo::setup() { //this->setSubTitleText("Summary"); button("ok")->onPress = [=](Mtype*) { this->bar(this); //Why is the this pointer being recognized here? }; } lambda的capture子句中的=是
void foo::setup()
{
//this->setSubTitleText("Summary");
button("ok")->onPress = [=](Mtype*)
{
this->bar(this); //Why is the this pointer being recognized here?
};
}
lambda的capture子句中的=
是否允许访问此指针。对我来说是吗?我的印象是使用这个
指针,我需要显式地捕捉这样的内容
button("ok")->onPress = [=,this](Mtype*)
{
this->bar(this); //Why is the this pointer being recognized here?
};
有什么建议吗?我想我会非常明确地说:
Lambda捕获
捕获是由零个或多个捕获组成的逗号分隔的列表,
可以选择从捕获默认值开始。唯一的捕获
默认值是
&(通过引用隐式捕获odr使用的自动变量)
及
=(通过复制隐式捕获odr使用的自动变量)
当前对象(*this)可以隐式捕获,如果
默认值存在。如果隐式捕获,则始终由
引用,即使捕获默认值为=。
是的。@ChrisDrew i think with=它只按值捕获封闭范围中的所有变量。这意味着这也包括在内?odr代表什么?@Rajeshwar odr代表一个定义规则。