Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22102

Lambda capture, initializers and nested struct

$
0
0

Could someone explain what is happening here (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;
}

When I capture nested struct I got:

'var' was not declared in this scope

On the other hand, capturing non-nested struct works. Also capturing with initialization works. Also all cases work in Visual Studio.


Viewing all articles
Browse latest Browse all 22102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>