static this() not executed

Robert M. Münch robert.muench at saphirion.com
Wed May 8 17:37:38 UTC 2019


// a.d
module a;
claas A {
	static myTemplate!A app;

	static this() {
		app = new myTemplate!A;
	}
}

void startup(State s){
	s.app = A.app;
}

// b.d
main(){
	State mainState = new State;

	startup(mainState);
}

The first problem I have is, that I can set a breakpoint on the static 
constructor but it's never executed. Later on startup() is executed but 
A.app is NULL. Why is the static constructor not run? I added a shared 
too, but same problem.

What I want to achieve is, that one instance of A is created on program 
start-up in a way that I can later use it. Or what's the best practice 
to instantiate at least one object of a class at startup?

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list