On Monday, 2 October 2017 at 09:34:29 UTC, Andrea Fontana wrote:
Anyway: you cant put a default destructor on struct

True. In which case you should either @disable this() (which presents its own set of issues) or hide b behind a @property function, something like:

struct S {
    B _b;

    @property
    B b() {
        if (_b is null) _b = new B();
        return b;
    }
}

This exact same issue also crops up for classes, since typeid(T).initializer is simply blitted over the newly allocated memory. At least for classes we could change the language such that:

class C {
    int[] p = new int[5];
}

is sugar for:

class C {
    int[] p;
    this() {
        p = new int[5];
    }
}

No such solution exists for structs, since they don't have default constructors.

--
  Biotronic
  • Struct bug? Andrea Fontana via Digitalmars-d-learn
    • Re: Struct bug? Biotronic via Digitalmars-d-learn
      • Re: Struct bug? Andrea Fontana via Digitalmars-d-learn
        • Re: Struct bug? Biotronic via Digitalmars-d-learn

Reply via email to