What is lifetime of lambda-derived implicit functors in C++ ?
Posted
by
Fyodor Soikin
on Stack Overflow
See other posts from Stack Overflow
or by Fyodor Soikin
Published on 2011-03-05T23:18:26Z
Indexed on
2011/03/05
23:25 UTC
Read the original article
Hit count: 312
The question is simple: what is lifetime of that functor object that is automatically generated for me by the C++ compiler when I write a lambda-expression?
I did a quick search, but couldn't find a satisfactory answer. In particular, if I pass the lambda somewhere, and it gets remembered there, and then I go out of scope, what's going to happen once my lambda is called later and tries to access my stack-allocated, but no longer alive, captured variables? Or does the compiler prevent such situation in some way? Or what?
© Stack Overflow or respective owner