Nóta
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as shíniú isteach nó eolairí a athrú.
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as eolairí a athrú.
'var' cannot be modified because it is being accessed through a const object
Remarks
A lambda expression that is declared in a const method cannot modify non-mutable member data.
To correct this error
- Remove the
constmodifier from your method declaration.
Example
The following example generates C3490 because it modifies the member variable _i in a const method:
// C3490a.cpp
// compile with: /c
class C
{
void f() const
{
auto x = [=]() { _i = 20; }; // C3490
}
int _i;
};
The following example resolves C3490 by removing the const modifier from the method declaration:
// C3490b.cpp
// compile with: /c
class C
{
void f()
{
auto x = [=]() { _i = 20; };
}
int _i;
};