65,184
社区成员




String(const String &newstr)
{
int length1 = strlen(newstr.s);
s=new char[length1+1];
length = length1;
strcpy(s,newstr.s);
}
就可以了
String String::operator+(const String &other)const
{
String newString;
if(!other.m_data)
newString = *this;
else if(!m_data)
newString = other;
else
{
newString.m_data = new char[strlen(m_data)+strlen(other.m_data)+1];
strcpy(newString.m_data,m_data);
strcat(newString.m_data,other.m_data);
}
return newString;
}
看看这里 string类型的重载