Why would an initialised struct pointer field be null in the struct's destructor?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 21 17:45:27 PDT 2017
On Monday, 22 May 2017 at 00:36:24 UTC, Stanislav Blinov wrote:
> I can't think of any case where you'd want preconditions on
> destructor when the object is in .init state.
I think we're actually saying the same thing: I mean the
destructor must be callable on .init so you might do like
struct Foo {
int* ptr;
~this() {
// might be called with ptr is null cuz of .init
// so wanna check
if(ptr !is null) free(ptr);
}
}
More information about the Digitalmars-d-learn
mailing list