Q:

addition of 2x2 matrices with operator overloading

I have the following code.
The code works fine without the operator + part.
It gives me 

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

and 

error: no match for ‘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 a 2x2 matrix :"<<endl;

    for (int i=0;i<2;i++) {
        for (int j=0;j<2;j++) {
cout <<"Give the elements of the 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 the matrix is :"<<det<<endl;

}

//compute addition
matrix matrix ::operator +(matrix &matr) {
matrix final[2][2];
for (int i=0;i<2;i++) {
    for (int j=0;j<2;j++) {
final[i][j]=mat[i][j]+matr.mat[i][j];
    }
}
cout <<"The addition of the two matrices is :"<<endl;

for (int i=0;i<2;i++) {
    for (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;
}

A:

That's because matrix final[2][2]; declares a 2-d array of matrices, so final[i][j] is of type matrix & and the relevant operators aren't defined. You must have meant double final[2][2];

