הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
'var': a by-value capture cannot be modified in a non-mutable lambda
Remarks
A non-mutable lambda expression cannot modify the value of a variable that is captured by value.
To correct this error
Declare your lambda expression with the
mutablekeyword, orPass the variable by reference to the capture list of the lambda expression.
Example
The following example generates C3491 because the body of a non-mutable lambda expression modifies the capture variable m:
// C3491a.cpp
int main()
{
int m = 55;
[m](int n) { m = n; }(99); // C3491
}
The following example resolves C3491 by declaring the lambda expression with the mutable keyword:
// C3491b.cpp
int main()
{
int m = 55;
[m](int n) mutable { m = n; }(99);
}