oop tutorials
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Mar 4 14:14:53 PST 2008
"Jesse Phillips" <jessekphillips at gmail.com> wrote in message
news:fqkejg$1vkn$1 at digitalmars.com...
> Just so you can ask that question, no not really but I'll tell you the
> difference.
>
> auto store = new Bike[10];
>
> Allocates memory on the heap, which means the function can return it.
>
> Bike[10] store;
>
> will allocate memory on the stack thus will not exist when the function
> returns. I had no reason not to use this, I just ended up not.
>
> And both arrays are static, thus there length will not change.
Nope. new Bike[10] allocates a new dynamically-sized array of length 10;
the type of that expression is Bike[], not Bike[10]. It's really sugar for
new Bike[](10). Thus its length can change.
It's not actually possible to allocate a statically-sized array on the heap
directly. You have to use a templated struct and allocate that.
More information about the Digitalmars-d-learn
mailing list