Why allow initializers of non-static members that allocate?

Salih Dincer salihdb at hotmail.com
Fri Jun 10 12:58:05 UTC 2022


On Friday, 10 June 2022 at 07:35:17 UTC, Bastiaan Veelo wrote:
> I have been foolish enough to make a mistake like this:
> ```d
> struct S
> {
>     int[] arr = new int[](5);
> }
> ```

Well, if the b's may not be equal, there's a simple solution.  
But why are a's like that, they're not static!

```d
void main()
{
   struct S(size_t size)
   {
     int[] arr = new int[size];
   }

   S!5 a1, a2;
   assert(a1.arr.ptr == a2.arr.ptr);

   S!5 b1;
   S!6 b2;
   assert(b1.arr.ptr != b2.arr.ptr);
}
```
SDB at 79


More information about the Digitalmars-d-learn mailing list