void String::operator=(const String &other) { if (&other==this) return; // Delete old first SAFE_DELETE_ARRAY(data); // Set length=other.GetLength(); data=new char[length+1]; other.ConvertToNullTermCharString(data,length+1); }
void String::operator+=(const String &other) { char *old_data=data; int old_length=length; length+=other.GetLength(); data=new char[length+1]; memcpy(data,old_data,old_length); other.ConvertToNullTermCharString(&data[old_length],other.GetLength()+1); data[length]=0; // do a null terminated string // Delete old data SAFE_DELETE_ARRAY(old_data); }
String::String(const String &orig) { length=orig.GetLength(); data=new char[length+1]; orig.ConvertToNullTermCharString(data,length+1); }