I am trying to add two matrices and get error when I add two matrices in the line rslt = m1+m2 using operator overloading. Both m1 and m2 are matrix classes.
Here is the code:
int main(int argc,char *argv[])
{
matrix * rslt;
//matrix *m1 = new matrix();
matrix m1;
m1.initMatrix(10,10,0,1);
m1.print();
//matrix *m2 = new matrix();
matrix m2;
m2.initMatrix(10,10,10,1);
m2.print();
rslt = m1 + m2;
//m1.printResult();
cout<<"done"<<endl;
}
matrix& matrix::operator+(const matrix& b)
{
int rows = this.getRowSize();
int cols = this.getColSize();
int seed = this.getSeed();
matrix *rslt = getResultMatrix(rows, cols, seed);
for(int i=0; i<rows; i++)
{
double res = 0.0;
for(int j=0; j<cols; j++)
{
rslt.m[i][j] = this.m[i][j]+b.m[i][j];
}
}
return rslt;
}