Thank you, but "problems" are so generic. Learn to be a little more descriptive and not make others do so much of your work.
Try this:
Code:
const String & String::operator +=(const String & str)
{
int newsize = getLength() + str.getLength() + 1; // Size of current + new string + '\0'.
char *temp = NULL;
if(newsize > size)
{
temp = new char[newsize];
strcpy(temp, buf);
delete []buf;
buf = temp;
size = newsize; // Accidentally left this out.
}
strcat(buf, str.buf);
stringlength = newsize;
return *this;
}
Disclaimer: I'm really more of a C programmer, so check it over to make sure I didn't break anything.