Deleting an element from an array

nobody somebody at somewhere.com
Tue Feb 3 09:11:35 PST 2009


"Jarrett Billingsley" <jarrett.billingsley at gmail.com> wrote in message 
news:mailman.637.1233680615.22690.digitalmars-d-learn at puremagic.com...
> On Tue, Feb 3, 2009 at 11:51 AM, nobody <somebody at somewhere.com> wrote:
>> Would you also happen to know why the following gives an error?
>>
>>  arr[1] = arr[$-1];    // main.d(11): Error: cannot assign to static 
>> array
>
> arr[1][] = arr[$-1][];
>
> You cannot reassign what fixed-size array references point to, but you
> can copy their contents.
>

Hm, I see.

> If this were an int[][], you would still probably want to do "arr[1][]
> = arr[$ - 1][]", since doing "arr[1] = arr[$ - 1]" would make arr[1]
> and arr[$ - 1] point to the same data; probably not what you would
> expect.

Well in this case I don't think it would be a problem, since right 
afterwards i do
arr.length = arr.length - 1;
But I can see how I have to be careful with this :) 




More information about the Digitalmars-d-learn mailing list