我现在有这样的东西
void foo::setup()
{
//this->setSubTitleText("Summary");
button("ok")->onPress = [=](Mtype*)
{
this->bar(this); //Why is the this pointer being recognized here?
};
}
lambda 捕获子句中的 =
是否提供对 this
指针的访问。在我的情况下是?我的印象是使用 this
指针,我需要像
button("ok")->onPress = [=,this](Mtype*)
{
this->bar(this); //Why is the this pointer being recognized here?
};
有什么建议吗?
最佳答案
我认为cppreference.com非常明确地声明:
Lambda capture
The captures is a comma-separated list of zero or more captures, optionally beginning with the capture-default. The only capture defaults are
& (implicitly capture the odr-used automatic variables by reference) and
= (implicitly capture the odr-used automatic variables by copy).
The current object (*this) can be implicitly captured if either capture default is present. If implicitly captured, it is always captured by reference, even if the capture default is =.
关于c++ - 是否 = 在 lambda 的捕获列表中捕获 this 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46905567/