Re: static array of pointers to dynamic arrays of ints problem...

2018-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/22/18 2:00 AM, WhatMeForget wrote: Surely a stupid mistake on my part, but why is the first array repeated? In addition to what Neia said, you shouldn't use pointers to dynamic arrays. Such things are really hard to allocate on the heap, since new int[] just makes an array, not a pointer

Re: static array of pointers to dynamic arrays of ints problem...

2018-04-21 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 22 April 2018 at 06:00:15 UTC, WhatMeForget wrote: foreach(i, elem; a) { int[] temp = new int[](5); .. a[i] = &temp; } You're taking the address of a local variable and persisting it beyond the variable's scope. This is not safe in general; compilers