C++运算符重载问题

friend Matrix operator + (Matrix &a,Matrix &b);

Matrix& operator = (Matrix &b);

[Error] no match for 'operator=' (operand types are 'Matrix' and 'Matrix')

#include<iostream>
using namespace std;

class Matrix{
private:
int arr[3][3];
public:
friend istream& operator >> (istream& in,Matrix &matrix);
friend ostream& operator << (ostream& out,const Matrix& matrix);
friend Matrix operator + (Matrix &a,Matrix &b);
void setArr(int i,int j,int data){
arr[i][j] = data;
}
int getArr(int i,int j){
return arr[i][j];
}
Matrix& operator = (Matrix &b);
};
istream& operator >> (istream& in,Matrix &matrix)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
in >> matrix.arr[i][j];
return in;
}
ostream& operator << (ostream& out,const Matrix &matrix){
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
out << matrix.arr[i][j] << " ";
out << endl;
}
return out;
}
Matrix operator + (Matrix &a,Matrix &b){
Matrix temp;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
temp.setArr(i,j,(a.getArr(i,j)+b.getArr(i,j)));
return temp;

}
Matrix& Matrix::operator = (Matrix &b){
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
arr[i][j] = b.getArr(i,j);
return *this;
}
int main()
{
Matrix a1,a2,a3,a4;
cin >> a1;
cin >> a2;
a4 = a2;
a3 = (a1+a4); //这里出错了
cout << a1 << endl;
cout << a2 << endl;
cout << a3 << endl;
return 0;
}

0

0

0