Is "auto t=T();" not the same as "T t;"?

Salih Dincer salihdb at hotmail.com
Tue Oct 25 17:54:16 UTC 2022


On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote:
> It's not a bug. They're pointing to the exact same instance of 
> `A` in memory:

I don't understand?  So I don't understand why it causes problems 
with dynamic arrays!  So why is there nothing wrong with the 
static array in the example below?


```d
import std.stdio, std.format;
void main()
{
   struct B
   {
     struct A {
       int i = 10;
     }
     //A[] a = [A.init];/*
     A[1] a = [A.init];//*/

     string toString() {
       return a[0].i.format!"%s";
     }
   }

   B[2] b;
   b.writeln;  // [10, 10]

   b[0].a[0].i = 0;
   b.writeln;  // [0, 10]

   b[1].a[0].i = 1;
   b.writeln;  // [0, 1]
}
```


More information about the Digitalmars-d-learn mailing list