Default initialization of structs?
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 17 04:10:12 PDT 2016
On Friday, 17 June 2016 at 10:53:40 UTC, Lodovico Giaretta wrote:
> struct Foo(T)
> {
> private int _bar = 1;
>
> this(int bar)
> {
> this._bar = bar;
> }
> }
>
> auto foo = Foo!(string)();
>
> This should do the trick.
Thanks, I forgot to mention I'm also doing lots of other stuff in
the constructor to private fields too.
struct Foo(T)
{
private int _bar;
private void* _baz;
this(int bar = 8)
{
this._bar = bar;
this._baz = malloc(this._bar);
}
}
So I have to at least run a constructor.
More information about the Digitalmars-d-learn
mailing list