หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
'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;
};