i have the following problem: my program crashes with sigabrt. I used gdb, and it turns out, that the program dies at a delete.
If i am correct, a delete causes sigabrt if the pointer was already deleted once.
However, i set a breakpoint just before the delete, and the pointer points to a perfectly valid "BinaryNode". I can even read out the data from the node just before the delete.
Then why is delete causing this error?
I tried to assign the value of one object to another one, like this:
A = B;
This was a bad idea. My class has a variable "Root" wich is a pointer. What happened, is that A's Root variable was overrided. When B's destructor was later called, the memory space where B's Root pointed, got deleted. However, A's Root variable still pointed to the now non-existent object, and when A's destructor was called, it tried to delete A's Root variable. And trying to delete something twice causes sysabrt.
The bottom line is, it is not a good idea to assign a variable to another, if it isn't a built in type, but a custom class. Unless of course you overloaded the "=" operator, and wrote a proper method for handling this.
I hope someone else will someday read this and not do the same error i did.
Better to use in this case std::auto_ptr which is not copyable and thus your assignment a=b; would have generated a compile error instead of a runtime error. Bet it would've saved you a couple of hours debugging time.