我在lambda中有lambda,我在捕获它时遇到了问题。有什么办法可以解决这个问题吗?也许这是某种别名?
auto late_connect = wakeup_signal_notify_to_connect.connect([this]()
{
auto wakeup = wakeup_signal_ptr->connect([this]()
{
//here I want to have this from level up
});
});我尝试使用别名如下所示:
auto late_connect = wakeup_signal_notify_to_connect.connect([this]()
{
auto* alias_to_this = this;
this->OnInvokeUpdate(); //here I can obtain thread local storage from boost
auto wakeup = wakeup_signal_ptr->connect([alias_to_this]()
{
alias_to_this->OnInvokeUpdate(); //here I cannot obtain thread local storage from boost
}
});
});伙计们,我忘了告诉你们,当我在lambda中使用lambda时,我遇到了来自boost的tls问题。
发布于 2015-07-10 18:27:02
这应该可以解决您的问题:
auto late_connect = wakeup_signal_notify_to_connect.connect([this]()
{
auto that = this;
auto wakeup = wakeup_signal_ptr->connect([that]()
{
//your stuff
});
});编辑:我仔细考虑过了,我的解决方案毫无意义。由内部lambda捕获的This仍然是level up中的相同this,因此您不必像在JavaScript的函数中那样创建别名。记住,lambda只能访问定义它们的作用域,而不能访问它们被调用的作用域。如果这不是您的问题,请提供更多信息。
https://stackoverflow.com/questions/31338302
复制相似问题