原题题目
代码实现
MyString(const MyString & a)
{
if(a.p == NULL)
p = NULL;
else
{
p = new char[strlen(a.p) +1];
strcpy(p,a.p);
}
}
void Copy(const MyString & w1)
{
p = new char[strlen(w1.p)+1];
strcpy(p,w1.p);
}
friend ostream & operator << (ostream & os, const MyString & a)
{
os<<a.p;
return os;
}
MyString & operator = (const MyString & a)
{
if(a.p == NULL)
p = NULL;
else
{
p = new char[strlen(a.p)+1];
strcpy(p,a.p);
}
return *this;
}
MyString & operator = (const char* a)
{
if(!a)
p = NULL;
else
{
p = new char[strlen(a)+1];
strcpy(p,a);
}
return *this;
}