c++ - addition of 2x2 matrices with operator overloading -


i have following code. code works fine without operator + part. gives me

error: no match ‘operator=’ in ‘final[i][j] = (((matrix*)this)->matrix::mat[i][j] + matr->matrix::mat[i][j])’

and

error: no match ‘operator<<’ in ‘std::cout << final[i][j]

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath>  using namespace std;   class matrix {  private :  int i,j; double mat[2][2];   public : matrix () { }  void getdata(); double determinant(); matrix operator + (matrix &);  };  //getdata void matrix :: getdata() { cout <<"please provide 2x2 matrix :"<<endl;      (int i=0;i<2;i++) {         (int j=0;j<2;j++) { cout <<"give elements of matrix : "<<endl; cin >> mat[i][j];         }         } }  //compute determinant double matrix :: determinant () {  double det;  det = mat[0][0]*mat[1][1] -mat[0][1]*mat[1][0];   cout <<"the determinant of matrix :"<<det<<endl;   }  //compute addition matrix matrix ::operator +(matrix &matr) { matrix final[2][2]; (int i=0;i<2;i++) {     (int j=0;j<2;j++) { final[i][j]=mat[i][j]+matr.mat[i][j];     } } cout <<"the addition of 2 matrices :"<<endl;  (int i=0;i<2;i++) {     (int j=0;j<2;j++){ cout << final[i][j];     } cout <<endl; }  }   int  main() {    matrix pinakas1,pinakas2;    pinakas1.getdata();    pinakas2.getdata();    pinakas1.determinant();    pinakas2.determinant();    pinakas1+pinakas2;       return 0; } 

that's because matrix final[2][2]; declares 2-d array of matrices, final[i][j] of type matrix & , relevant operators aren't defined. must have meant double final[2][2];


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -