getting rid of immutable (or const)
drug
drug2004 at bk.ru
Thu Sep 5 12:15:51 UTC 2019
05.09.2019 14:28, berni пишет:
> On Thursday, 5 September 2019 at 11:22:15 UTC, drug wrote:
>> 05.09.2019 14:17, berni пишет:
>>>> Point[long] q;
>>>>
>>>> q[1] = Point(3);
>>>
>>> Leads to:
>>>
>>>> test.d(7): Error: cannot modify struct q[1L] Point with immutable
>>>> members
>>>
>>>
>> But why do you try to modify immutable data? What is your point? Could
>> you describe you use case?
>
> That's probably, what I don't understand. I've got a Point, which should
> not be modified. I put it in a container (q) and later I get it out
> there again. It should still be the same Point as before. I modify the
> container, not the Point, don't I?
One solution could be using either pointer to `const(Point)` or class
here (to avoid pointer using) https://run.dlang.io/is/rfKKAJ
More information about the Digitalmars-d-learn
mailing list