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) return *this; delete m_pData; m_pData = NULL; if(!object.m_pData) return *this; m_pData = new char[strlen(object.m_pData)];//此处不管加不加1都不能处理 m_pData = NULL 情况 strcpy不支持 strcpy(m_pData, object.m_pData); return *this; } };
时间: 2024-10-14 16:56:12