February 04, 2004 Strange crash in destructor | ||||
---|---|---|---|---|
| ||||
In this code the destructor crashes the program; I can't even catch the exception. Strange thing is that it works fine if name is a char[] or if I don't modify its value.
class Foo
{
char* name;
this()
{
name = new char[4];
name[0 .. 4] = "foo\0";
}
~this()
{
delete name; //this causes it
}
}
int main()
{
Foo foo = new Foo;
return 0;
}
--
Christopher E. Miller
www.dprogramming.com
|
Copyright © 1999-2021 by the D Language Foundation