scope front vs [0]

vitamin vit at vit.vit
Wed Nov 11 18:35:07 UTC 2020


Hello,
Why does expression 'foo = bars[][0].foo' work but 'foo = 
bars[].front.foo' doesn't?

example:


class Foo{}

struct Bar{
	Foo foo;
}

void main()@safe{
	import std;

     Foo foo;
     scope Bar[] bars = [Bar.init];

     foo = bars[][0].foo;		//OK, WHY?
     foo = bars[].front.foo;		//Error: scope variable bars 
assigned to foo with longer lifetime
}


More information about the Digitalmars-d-learn mailing list