struct S { string s; }
void method()
{
const S s = { "s" };
s.s = "l"; // Error
}
I can't understand why a compile-error is being generated here. From my understanding, making a struct-referencing variable const
should make the variable itself immutable (only s = { "m" }
after s
initialization should generate error), not the structure itself (so s.s = "l"
should pass OK). Why const makes both the variable and the struct immutable?