Alternative destructors, do/should we have them?

Atila Neves atila.neves at gmail.com
Thu Jul 5 16:12:08 UTC 2018


On Thursday, 5 July 2018 at 10:57:51 UTC, Dukc wrote:
> D does not have default constructors for structs, but I have 
> thought that this might get around the problem:
>
> [...]

You already have that capability:

struct HandGrenade {
     void* ptr;
     void destroy() {
         import core.stdc.stdlib: free;
         free(ptr);
     }
}


This isn't a great example since it's perfectly fine to pass null 
to core.stdc.stdlib.free.

Atila


More information about the Digitalmars-d mailing list