Related newsgroup thread:
http://forum.dlang.org/thread/[email protected]?page=1
The following constructor fails compilation in a way that suggests some error in the order members are initialized.
import std.stdio;
struct Foo {
int i;
/* This line is pertinent: */
@disable this();
this(int i) {
this.i = i;
}
}
struct FooList {
Foo[3] foos;
this(int) {
/* This constructor fails compilation with dmd 2.070.0:
*
* Error: field 'foos' initialization is not allowed in loops or
* after labels
*
* There are at least two interesting ways of passing compilation:
*
* a) Either add the following line BEFORE the loop:
* foos[0] = Foo(10);
*
* b) Or remove 'ref' in the loop AND add the following line AFTER
* the loop:
* foos[0] = Foo(10);
*/
foreach (ref f; foos[]) {
writeln(f.i);
}
}
}
void main() {
}
Ali
Comment #1 by robert.schadek — 2024-12-13T18:46:56Z