D - 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
Feb 04 2004
That class wasn't needed, this does it: char* f = new char[4]; f[0] = 'f'; delete f;
Feb 04 2004