array copy/ref question

Jesse Phillips jessekphillips at gmail.com
Tue Aug 12 07:12:52 PDT 2008


On Tue, 12 Aug 2008 02:42:17 +0000, Jesse Phillips wrote:

> main( string[] args )
> {
>     int[] test = [ 1, 2, 3, 4 ];
>     int[] copy = new int[4];
> 
>     copy[]  = test;
>     test[1] = 11;
> 
>     assert( test[1] == 11 );
>     assert( copy[1] == 2 );
> 
>     writefln( "Copy: test[1] %d copy[1] %d", test[1], copy[1] );
> }

I know I created that first one to be smaller, here is what it was 
supposed to be.

void main( string[] args )
{
    int[] test = [ 1, 2, 3, 4 ];
    int[] copy;

    copy = test;

    copy[]  = test;
}



More information about the Digitalmars-d mailing list