Error: cannot modify struct arr[0] MyStruct with immutable members
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 11 06:44:09 PDT 2015
On Monday, 11 May 2015 at 13:37:27 UTC, ref2401 wrote:
> Why does it happen?
You'd just be writing to the immutable memory through a different
name.
Consider if someone took a reference to one of those immutable
ints, expecting it to never change. Then you wrote a new struct
over the same location with different values. Then the ints
pointed to by that reference suddenly change, despite allegedly
being immutable!
Assigning a struct in-place is the same as assigning all its
members.
More information about the Digitalmars-d-learn
mailing list