Operator Overloading problem
Code:
class Matrix
{
private:
string _name;
int _row;
int _col;
double ** _mat;
public:
//class methods
};
Code:
//sets the data of a matrix given a matrix. assignment operator overloading
Matrix & Matrix::operator = (const Matrix & mMatrix)
{
int i,j;
_row = mMatrix._row;
_col = mMatrix._col;
_name = mMatrix._name;
_mat = new double *[_row];
for(i=0;i<_row;i++)
{
_mat[i] = new double [_col];
for(j=0;j<_col;j++)
{
_mat[i][j] = mMatrix._mat[i][j]; //fails here
}
}
return *this;
}
why does the code above fail?