I have a funtion executing a loop, which semes to be progressing normally until the debugger halted with this message;

Program received signal SIGSEGV, Segmentation fault.

I pulled up a a backtrace and it had "normal lookuing" addresses for the this pointer and the reference variable.

I could probably figure this out if I only knew what he hell the debugger was trying to tell me.! Anyone?

maybe using an uninitialized pointer ? Can't say for sure until you post some code.

Thanks, I found it.
I had left out the definition of "i" in a "i,j type for loop"
The i=itsLen was omitted in the 2nd loop.
I guess that caused the program to attempt to put a string of some number of charactors into a string of size zero???

//creates a new String by adding current
//String to rhs
String String::operator+(const String& rhs)
{
    int totalLen = itsLen + rhs.GetLen();
    String temp(totalLen);
    int i, j;
    for (i =0; i < itsLen; i++)
        temp[i] = itsString[i];
    for (j= 0, i=itsLen; j < rhs.GetLen(); j++, i++)
        temp[i] = rhs[j];
    temp[totalLen]='\0';
  return temp;
 }

The other thing i don't quite understand is how the string is returned if the previous line sets the array to null? Is this something the compiler resolves, even though the sequence is wrong?
this code now works as advertised...

It seems you have taken the long way around with that entire function. This should do it.

//creates a new String by adding current
//String to rhs
String String::operator+(const String& rhs)
{
    String temp;
    temp = itsString + rts;
    return temp;
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.