1
int a = 3;
auto f = [a] (int a) { return a > a; }

Q:capture the local variable names a and lambda have a differentiated method?

I think it is within the scope of a parametric a is independent of the external local variables a, would like to know whether there is something like this pointer distinction.

zhm
  • 3,513
  • 3
  • 34
  • 55
Yang_Guang
  • 11
  • 1

1 Answers1

3

When the compiler processes a lambda, what it does is basically create a special class that it instantiates. The actual lambda function becomes a operator() function, and the captured variables becomes member variables in this special class.

That means the normal scoping rules apply, where local variables and arguments shadows member variables.

So in your case a is the argument, not the captured variable.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621