www.digitalmars.com         C & C++   DMDScript  

D - Call delete from destructor ?

reply Silencer <Silencer_member pathlink.com> writes:
Why when I call delete from destructor of class B, my program is stopped and
don't answer. It's a bug or feature ? (Compiled with dmd 0.79, 0.78 under linux)
Program output :
------------
B()
A()
~B()
----------
// Program listing
class A
{
this() { printf("A()\n"); }
~this() { printf("~A()\n"); }
}

class B
{
this() {
printf("B()\n");
m_a = new A;
}
~this() {
printf("~B()\n");
delete m_a; // Error ?!!!
}   
A m_a;
}

int main(char[][] args)
{
B b = new B;
delete b;
return 0;
}
Jan 29 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
Silencer wrote:

Why when I call delete from destructor of class B, my program is stopped and
don't answer. It's a bug or feature ? (Compiled with dmd 0.79, 0.78 under linux)
Program output :
------------
B()
A()
~B()
----------
// Program listing
class A
{
this() { printf("A()\n"); }
~this() { printf("~A()\n"); }
}

class B
{
this() {
printf("B()\n");
m_a = new A;
}
~this() {
printf("~B()\n");
delete m_a; // Error ?!!!
}   
A m_a;
}

int main(char[][] args)
{
B b = new B;
delete b;
return 0;
}


  

B() A() ~B() ~A() -- -Anderson: http://badmama.com.au/~anderson/
Jan 29 2004