Uh... destructors?

%u wfunction at hotmail.com
Tue Feb 22 11:24:24 PST 2011


> What's the problem with a pure destructor? It only means you can't access global variables.
If the object holds a pointer to somewhere, you can still affect that somewhere.

> In fact, if your struct's destructor isn't pure, how can you use it as local variable inside
of a pure function?

The problem is that a pure destructor makes no sense because "pure" means that a function has
no side effects. So anything that a pure function does would need to be strictly reflected only
in its output, and in nothing else... and yet, a destructor has no output (and no input
either), so it's logically not allowed to perform any action with side effects... in other
words, it can't do _anything_, just like in functional programming.

Unless I'm misunderstanding the meaning of "pure", I don't see how a destructor marked as
"pure" would be meaningful. (The same reason applies to const.)


More information about the Digitalmars-d mailing list