#include <cstdio>
struct test {
test() : _a{} { }
int getA() { return _a; }
int setA(int a) { return _a = a; }
int _a;
};
template<class T>
struct init {
init() {
//init objects
t1.setA( 10 );
t2.setA( 10 );
}
static test t1;
static test t2;
};
//declare static objects
template<class T> test init<T>::t1;
template<class T> test init<T>::t2;
//test instantiation
template test init<void>::t2;
//init t1 and t2
init<void> I;
int main() {
printf( "t1.A = %d\n", I.t1.getA() );
printf( "t2.A = %d\n", I.t2.getA() );
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KCnN0cnVjdCB0ZXN0IHsKCgl0ZXN0KCkgOiBfYXt9IHsgfQoJCglpbnQgZ2V0QSgpIHsgcmV0dXJuIF9hOyB9CglpbnQgc2V0QShpbnQgYSkgeyByZXR1cm4gX2EgPSBhOyB9CgoJaW50IF9hOwkKfTsKCnRlbXBsYXRlPGNsYXNzIFQ+CnN0cnVjdCBpbml0IHsKCQoJaW5pdCgpIHsKCQkvL2luaXQgb2JqZWN0cwoJCXQxLnNldEEoIDEwICk7CgkJdDIuc2V0QSggMTAgKTsKCX0JCgkKc3RhdGljIHRlc3QgdDE7CnN0YXRpYyB0ZXN0IHQyOwp9OwoKLy9kZWNsYXJlIHN0YXRpYyBvYmplY3RzCnRlbXBsYXRlPGNsYXNzIFQ+IHRlc3QgaW5pdDxUPjo6dDE7CnRlbXBsYXRlPGNsYXNzIFQ+IHRlc3QgaW5pdDxUPjo6dDI7CgovL3Rlc3QgaW5zdGFudGlhdGlvbgp0ZW1wbGF0ZSB0ZXN0IGluaXQ8dm9pZD46OnQyOwoKLy9pbml0IHQxIGFuZCB0Mgppbml0PHZvaWQ+IEk7CgppbnQgbWFpbigpIHsKCQoKCXByaW50ZiggInQxLkEgPSAlZFxuIiwgSS50MS5nZXRBKCkgKTsKCXByaW50ZiggInQyLkEgPSAlZFxuIiwgSS50Mi5nZXRBKCkgKTsKCQoJcmV0dXJuIDA7Cn0K