Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding .init in custom type in D

I remember having read somewhere that it's possible to override the .init property of custom types in D. I'd like to do this for a struct I've created, but I'm not finding any way to do this, especially since default constructors aren't allowed. Is this actually possible, and if so, how can I do this?

like image 493
Mark LeMoine Avatar asked Jun 09 '11 21:06

Mark LeMoine


1 Answers

you can specify the init values of the fields (with compile time vars only)

struct foo{
    int a=0;
    real b = 5.0;
}

foo.init will then be equal to foo(0,5.0)

like image 124
ratchet freak Avatar answered Nov 22 '22 15:11

ratchet freak