Matrix& Matrix::operator=(const Matrix &mp) {
if (mp.row_n != row_n||mp.column_n != column_n) {
std::cout << "Error , size not match" << std::endl;
return this;
}
/
for (int i = 0; i < row_n; i++) {
delete[] element[i];
}
delete[] element;
element = (int **)new int*[mp.row_n];
for (int i = 0; i < column_n; i++)
element[i] = new int[mp.column_n];
*/
for (int i = 0; i < row_n; i++)
for (int j = 0; j < column_n; j++)
element[i][j] = mp.element[i][j];
return *this;
}
注釋中的那一句加上之後程序就報錯說*** Error in `./temp': double free or corruption (out): 0x0000000000caf1d0 ***
當然可以了,指針指向的區域,可以釋放掉再從新分配的