Creating an array of default-constructed class instances

Ali Çehreli acehreli at yahoo.com
Sun Feb 10 08:25:41 PST 2013


On 02/10/2013 03:18 AM, monarch_dodra wrote:
 > On Sunday, 10 February 2013 at 09:48:04 UTC, Jos van Uden wrote:

 >> auto things = new Thing[10];
 >> fill(things, new Thing(5));

 > What you did just right there is allocate a *single* thing _instance_
 > and then place 10 _references_ to that same thing in the array.

And in case that is what we really wanted, there is the simpler but 
sometimes confusing array-wise syntax:

     auto things = new Thing[10];
     things[] = new Thing(5);

Ali



More information about the Digitalmars-d-learn mailing list