array copy/ref question

telengard bsturk at comcast.net
Tue Aug 12 13:16:43 PDT 2008


Sclytrack Wrote:

> == Extrait de l'article de « Jesse Phillips (jessekphillips at gmail.com) »
> > 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] );
> > > }
> 
> copy = test.dup;  //Is this what you want?
> 

Just found that and it does seem to do what I want.  Seems like I have other issues though from reading the responses.  Much to learn.   :)

I think I'm projecting too much of my python stuff onto D.  I thought I could just slice an array into a newly declared one as I would in python.

thanks for the info everyone, much appreciated.

~telengard



More information about the Digitalmars-d mailing list