> that was why I included just the relevant portions
http://www.eelis.net/iso-c++/testcase.xhtml
A testcase consisting of randomly copy&paste'd bits of code that you thought were relevant can obviously not reproduce the problem. Worse, such testcases force your perception of the problem upon us, preventing us from taking a fresh look at it and making an unbiased analysis. |
It's good that you try to simplify the code, but you need to make sure that we can compile it nad run it and have the same errors as you.
> what tool can I use to debug a program?
a debugger.
By instance gdb, your IDE probably provides a nice interface to it.
When your program hangs you interrupt it (<C-c>) and it will show you the line that was executing.
You may also consider using valgrind to detect bad memory access.
> what is a backtrace?
http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_42.html
A backtrace is a summary of how your program got where it is. |
the functions called and their arguments.
>> The class one takes ownership of the next cell.
> What do you mean by this please?
in the class' code, when a cell dies its neighbour is killed.
1 2 3 4
|
nodeType<elemType>::~nodeType()
{
delete link;
}
|
that doesn't happen with the struct.
> ensure that before the copy is performed, the pointer of the destination object is NULLed
> I think this requirement is a standard segment of copy constructors I've seen.
The purpose of the constructor is to initialize its members, so the members are uninitialized there.
`link' points to garbage there, it cannot possible point to newly allocated memory. It isn't sure that it points to NULL either.
Perhaps you are confused with the assignment operator.
UB: undefined behaviour. You've got a logic error and the worst part is that your program may not crash, and even give the correct answer.
DEA: Don't Ever Abbreviate