Deleting an element from an array

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Feb 3 09:03:27 PST 2009


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.

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.


More information about the Digitalmars-d-learn mailing list