Is this code : import std.stdio; import std.conv; struct pt1{ p val; pt1* next; } struct p{ int val; string toString(){ return(to!string(val)); } } void thefun(pt1 x){ writeln(&x); } void main(){ auto p0 = p(1); auto p1 = p(2); auto p2 = p(3); auto p3 = p(4); p[] arr = [p0,p1,p2,p3]; writeln(arr); foreach(r;arr){ thefun(pt1(r)); } }
supposed to output this: 1 2 3 4 BFE61E28 BFE61E28 BFE61E28 BFE61E28 //Note all the addresses are the same It is expected that using a struct literal(or default constructor) on a bucle reuses the same address? I got hit by this trying to do a tree structure builder, for hours searching aand finally found this (feature | bug). If so, how I could get a new struct to void changing (in a unnoticeable way) the same struct i just set. thanks. g g