[英]Lambda capture, initializers and nested struct
有人可以解釋這里發生的事情(GCC 7.3):
#include <thread>
#include <iostream>
struct A
{
struct B {};
};
int main()
{
int var = 0;
std::thread([c=A::B(), var](){ }); // error: ‘var’ was not declared in this scope
std::thread([c=A(), var](){ }); // OK
std::thread([c=A::B(), var=var](){ }); // OK
return 0;
}
當我捕獲嵌套結構時,我得到:
“var”未在此范圍內聲明
另一方面,捕獲非嵌套結構有效。 還捕獲初始化工作。 此外,所有案例都適用於 Visual Studio。
必須是 GCC 7.x 中的一個錯誤,因為 8.1 接受它。 https://godbolt.org/z/xXw6qN
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.