String类的赋值函数
String & String::operator =(const String &other)
{
if (this == &other)
{
return *this;
}
delete m_data;
int length = strlen(other.m_data);
m_data = new char[length + 1];
strcpy(m_data, other.m_data);
return *this;
}
问题1:if (this == &other)为什么不能写成if (*this == other)?
问题2:return *this 为什么不能写成 return this,书上说是为了实现赋值的链式表达,高手能否详细介绍一下返回一个引用可以实现链式表达?