[Issue 15994] Trivial code compiled with dmd ends with code 11 !?

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu May 5 07:44:19 PDT 2016


--- Comment #2 from Adam D. Ruppe <destructionator at gmail.com> ---
Not a bug in D, simple programmer error. Pointers and references (not that all
class objects are implicitly references, like Java or C#, but unlike C++) are
automatically initialized to null exactly so it segfaults consistently to tell
you that you made a mistake.

To fix it, you need to initialize the object before use.

For your case, you might just make B a struct instead of class. Classes'
strength is found in interfaces and inheritance and you don't need that here,
so struct is probably more appropriate. Structs are not references, so they
will never be null.


More information about the Digitalmars-d-bugs mailing list