www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Question about initialization

reply seany <seany uni-bonn.de> writes:
Consider initializing a dictionary or associative array :

     T[U] AA;

For example :

     double [int] AA;


This will be dynamic in size.

Now consider initializing a dynamic array :

     T[] A = new T[] (0);

or

     U[][] B = new U [][] (0,0);


This will also be dynamic in size.

In my untrained eye, this seems haphazard. One requires the use 
of the new keyword, the other does not. Why is it? Has It got 
something to do with random access mechanism? I would like to 
know the rationale please.
Jun 04
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 4 June 2021 at 11:27:05 UTC, seany wrote:
 In my untrained eye, this seems haphazard. One requires the use 
 of the new keyword
It doesn't. T[] a; just works. it is an array of length 0.
Jun 04