Events
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this article
'var': you cannot capture a variable that has a managed or WinRTtype
You cannot capture a variable that has a managed type or a Windows Runtime type in a lambda.
- Pass the managed or Windows Runtime variable to the parameter list of the lambda expression.
The following example generates C3498 because a variable that has a managed type appears in the capture list of a lambda expression:
// C3498a.cpp
// compile with: /clr
using namespace System;
int main()
{
String ^ s = "Hello";
[&s](String ^ r)
{ return String::Concat(s, r); } (", World!"); // C3498
}
The following example resolves C3498 by passing the managed variable s
to the parameter list of the lambda expression:
// C3498b.cpp
// compile with: /clr
using namespace System;
int main()
{
String ^ s = "Hello";
[](String ^ s, String ^ r)
{ return String::Concat(s, r); } (s, ", World!");
}