Question about mutable arrays
Steven Schveighoffer
schveiguy at yahoo.com
Mon Nov 23 05:37:48 PST 2009
On Fri, 20 Nov 2009 09:42:55 -0500, A Bothe <info at alexanderbothe.com>
wrote:
> These lines were just a basic idea...of course I have to fill the
> array...
>
> string[] a=new string[2];
>
> a[0]="A";
> a[1]="B";
>
> my idea was to create a list class to store something in it...
>
> class List(T)
> {
> T[] arr;
>
> // ctors and such
>
> void opIndexAssign(T e,int i)
> {
> arr[i]=e; // And here it throws the exception that arr is not
> mutable...
> }
> }
First, it looks like you are assuming you can just assign an element of an
array without ensuring the array is large enough to hold it. This works
in some dynamic languages but not D.
Second, if you have done that properly, this should work if T is string,
because although string is not fully "mutable", it is rebindable.
Can you post a full code example, and the exact error message you get?
It's hard to guess what problem you are running into. You don't need to
post full code, just enough to make the error occur.
-Steve
More information about the Digitalmars-d-learn
mailing list