string& string::operator=(const string& str){
if( this==&str )
return *this;
delete []data;
m_data = null;
m_data = new char[ strlen(str.data)+1] ;
strcpy(data, str.data);
return *this;
}
string& string::operator=(const string& str){
if( this != &str){
string temp(str);
char *p = temp.data;
temp.data = data;
data = p;
}
return *this;
}C++中重载赋值运算符应该注意的地方,布布扣,bubuko.com
原文:http://blog.csdn.net/swagle/article/details/19966557