dynamic array creation

Myron Alexander someone at somewhere.com
Wed May 9 12:07:40 PDT 2007


Jarrett Billingsley wrote:
> "orgoton" <orgoton at mindless.com> wrote in message 
> news:f1t00h$h6i$1 at digitalmars.com...
>> Assume "Foo" to be a class:
>>> int[] ar = new int[10];
>> If you put
>> foo[] ar=new foo[10];
>> will will generate an array with 10 _instances_ of foo (using default 
>> ctor).
> 
> You're thinking C++.  D never calls constructors unless you use 'new'.
> 
> class A
> {
>     this()
>     {
>          writefln("ctor");
>     }
> }
> 
> void main()
> {
>     A[] a = new A[10]; // nothing is printed
>     writefln(a[0]); // null
> } 
> 
> 

Am I right if I say that the two forms of dynamic array creation are 
effectively the same?


More information about the Digitalmars-d-learn mailing list