Cannot call mutable method on final struct
Carlos Santander
csantander619 at gmail.com
Mon Sep 10 06:32:12 PDT 2007
Christopher Wright escribió:
> Carlos Santander wrote:
>> I don't use D 2.0, but here it goes...
>>
>> string is const(char)[] or const char[] or something like that... It's
>> const, anyway, so you aren't supposed to modify it. Replace "string
>> value" with "char[] value".
>>
>
> If I use char[] rather than string, it fails with the error message I
> stated (and indeed, in the original, I used char[] accidentally). If I
> just call Box.toString and don't do anything with the returned string,
> it fails with the same error message.
>
> 'string ~= whatever' is valid because the string is not final. The
> compiler rewrites it as 'string = string ~ whatever'.
>
> New minimal test case:
> ---
> import std.boxer;
> void main () {
> foreach (b; boxArray(9, 'b')) {
> b.toString;
> }
> }
> ---
In that case, I guess the workaround (ref b) is not really a workaround but the
way it should be done.
--
Carlos Santander Bernal
More information about the Digitalmars-d-learn
mailing list