Default initialization of structs?
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 17 03:50:55 PDT 2016
I have a struct where I need to perform default initialization of
some members but the compiler doesn't allow to define a default
constructor which allow optional arguments.
struct Foo(T)
{
private int _bar;
this(int bar = 1)
{
this._bar = bar;
}
}
auto foo = Foo!(string) // error
Are there any patterns or idioms I could use to get the desired
result? Or is it just the case if I use a constructor I have to
pass values to it?
More information about the Digitalmars-d-learn
mailing list