Robert Clipsham Wrote:
> On 18/02/10 15:13, Jesse Phillips wrote:
> > Please place them on Wiki4D, probably a sub-section under AMD64. If you
> > don't I will, but I'll give you a chance :)
> >
> > http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD/Compiler/DMD
>
> Done, I hope it'
Why, in the following piece of code, destructor for 'x' is never called?
class A{ char [] s; this(char [] o_s){ s = o_s; } ~this(){ writefln(s); }; }
void main(){
A y;
{
scope A x = new A("x".dup); y = new A("y".dup);
x = y; //
}
}
output:
y // where is x
Destructors fo
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Zarathustra wrote:
> Why, in the following piece of code, destructor for 'x' is never called?
>
Because it is not guaranteed to be called.
http://www.digitalmars.com/d/2.0/class.html#destructors
According to the spec, for the cases you've provided
div0:
> scope x = new A("x");
> y = new A("y");
> x = y;
In my opinion it's better to not reassign references of scoped objects.
In real programs where possible it's better to write boring and stupid code :-)
Bye,
bearophile
I want to initialize an immutable struct but I'm encountering two difficulties
and I can't find the answer in the documentation. (Wouldn't it be nice if
someone wrote a book?)
The primary difficulty is that I can't use a static initializer but need to use
a constructor instead. But the construc