Compiler Error C3495

Visual Studio 2015
 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C3495.

var': a lambda capture must have automatic storage duration

You cannot capture a variable that does not have automatic storage duration, such as a variable that is marked static or extern.

To correct this error

  • Do not pass a static or extern variable to the capture list of the lambda expression.

The following example generates C3495 because the static variable n appears in the capture list of a lambda expression:

// C3495.cpp  
  
int main()  
{  
   static int n = 66;  
   [&n]() { return n; }(); // C3495  
}  

Lambda Expressions
(NOTINBUILD)Storage-Class Specifiers

Show: