实现赋值运算符重载函数,确保:
A = B = C 赋值
class Solution {
public:
char *m_pData;
Solution() {
this->m_pData = NULL;
}
Solution(char *pData) {
this->m_pData = pData;
}
// Implement an assignment operator
Solution operator=(const Solution &object) {
// write your code here
if(this != &object) {
delete []m_pData;
if(object.m_pData!=NULL) {
m_pData = new char[strlen(object.m_pData)+1];
strcpy(m_pData,object.m_pData);
}
}
return *this;
}
};原文:http://blog.csdn.net/susser43/article/details/46406113