I’m very well aware of static constructors, but what does it mean to have a static this() outside of a class?
import std.stdio;
static this(){
int x = 0;
}
int main(){
writeln(x); // error
return 0;
}
And how do I access the variables define in static this() ?
This is the module constructor. You can read about them here: http://www.digitalmars.com/d/2.0/module.html
Obviously, you can’t access
xin your sample, because it’s a module constructor’s local variable, just as well as you couldn’t have done it with a class constructor’s one. But you can access module-scope globals there (and initialise them, which is what the module constructors are for).