back to arays
Derek Parnell
derek at psych.ward
Mon May 15 00:56:55 PDT 2006
On Mon, 15 May 2006 10:05:22 +0300, Max Samuha wrote:
> I thought array references are similar to object references like in C#
> (actually, thay are object references in C#) and that was my mistake:
>
> int[] a = new int[20];
> int[] b = a;
>
> a.length = 40; // a is copied and b is not updated to point to a's
> data;
>
> Does it mean that anytime i change an array, i have to manually update
> all references to it or should i wrap my array in an Array class so
> that all references to any instance of that array remain valid?
>
> If the question have been already discussed please refer me to the
> right thread. Thanks
I assume for some valid reason you want this behaviour...
int[] a = new int[20];
int[] b = a;
int[] c = a;
a[0] = 17;
writefln("%s %s", b[0], c[0]); // Displays 17 17
The simplest way to do this is ...
int[] a = new int[20];
int[]* b = &a;
int[]* c = &a;
a[0] = 17;
writefln("%s %s", b[0], c[0]); // Displays 17 17
I'm not sure why one would need this behaviour though. Why do you need two
identifiers in the same scope to reference the same data?
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
15/05/2006 5:49:08 PM
More information about the Digitalmars-d-learn
mailing list