Howdy,
I seem to be having trouble with the following function:
void OtherClass::copy_this( int index, MyClass &class_obj)
{
if(index < MAX_index)
class_obj = array_of_MyClass[index];
}
OtherClass maintains an array of MyClass objects, and I would like this function to copy a selected object out of the array into the provided class_obj.
When I run, the program has a segmentation fault when it reaches this function. Running it in gdb and looking at the backtrace reveals that when it hits the assignment line, execution jumps backwards almost 100 lines into the middle of a completely different function. The line it jumps to is:
temp_obj = array_of_MyClass[other_index]
And the relevant output from the gdb backtrace is:
#0 0x0000003c7ae7256c in memcpy () from /lib64/tls/libc.so.6
#1 0x000000000043264e in MyClass::operator= (this=0x4c0000004c, _ctor_arg=@0x7fbffd8228) at ../location.cpp:156
#2 0x0000000000432569 in OtherClass::copy_this (this=0x7fbffd8220, index=0, section=@0x4c0000004c) at ../location.cpp:254
Obviously it's the same type of operation, but why on earth would execution move like that? I have no longjumps, gotos, etc. anywhere in the program. I also do not have user-defined assignment operators, copy constructors, etc., so the "operator=" from the backtrace is puzzling.
Before anyone asks, no, I cannot post the whole code. (Sorry!) I realize that may make it impossible to identify my problem; if this is the case, just let me know.
Thanks in advance!
After running through it again and testing a couple of "simplest use" cases, it seems that the problem is actually introduced somewhere earlier in execution, so it's back to the drawing board for me. Thank you all for your help!