Edit

Share via


Compiler Error C3480

'var': a lambda capture variable must be from an enclosing function scope

The lambda capture variable is not from an enclosing function scope.

To correct this error

  • Remove the variable from the capture list of the lambda expression.

Examples

The following example generates C3480 because the variable global is not from an enclosing function scope:

// C3480a.cpp

int global = 0;
int main()
{
   [&global] { global = 5; }(); // C3480
}

The following example resolves C3480 by removing the variable global from the capture list of the lambda expression:

// C3480b.cpp

int global = 0;
int main()
{
   [] { global = 5; }();
}

See also

Lambda Expressions