Questions about initialization of array of objects
Andrey
andr-sar at yandex.ru
Sat Jan 12 15:14:57 PST 2013
I think this might be a problem because every template instance
creates separate independent class, as far as I know.
Well, maybe you can use function pointer and create static
constructor. More job need to be done, but the resulting class
doesn't lose much and even become more flexible, configurable;
final class StaticMyClass {
static void _myfun() {
writeln("Hello!");
}
}
class MyClass(T) {
uint x, y;
static void function() myfun;
static this() {
MyClass.myfun = &StaticMyClass._myfun;
}
//still you have additional memory consumed by static
constructor function;
this() {
this.myfun();
}
}
void main() {
auto obj = new MyClass!int();
}
More information about the Digitalmars-d-learn
mailing list