开发者

Overriding .init in custom type in D

开发者 https://www.devze.com 2023-03-12 08:28 出处:网络
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 t

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?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消