I have an inner lambda that uses one of the referenced variables of the outer lambda like this:
int x=0;
auto outer=[&](){
return [&](){
x=5;
};
};
auto inner= outer();
inner();
std::cout << x;
I tried it. It worked well. However, I want to make sure that there is no dangling reference here. Is there?
x
, and since you didn't leave the scope where it was defined - it isn't a dangling reference. But, I'll let more knowledgeable people on SO answer it. – Footstalk