求大神指导,关于文件流操作符重载的有关问题

求大神指导,关于文件流操作符重载的问题
我写了个矩阵相加的程序,结果编译不过去了,是流运算符重载的问题
//======================
#include<fstream>
#include<cstdlib>
#include<cmath>
using namespace std;
ifstream fin ("Matrix.in");
ofstream fout("Matrix.out");

const int MAX_NUMBER=300;

class Matrix
{
    public:
        int length,width;
        int a[MAX_NUMBER][MAX_NUMBER];
        Matrix():length(3),width(3){memset(a,0x00,sizeof(a));}
        void set_val(int l,int w){length=l;width=w;}
        ifstream& operator >>(ifstream& in)
        {
            for(int i=0;i<width;i++)
            for(int j=0;j<length;j++)
            in>>a[i][j];
            return in;
        }
        ofstream& operator << (ofstream& o)
        {
            for(int i=0;i<width;i++)
            {
                for(int j=0;j<length;j++)
                {
                    o<<a[i][j]<<' ';
                }
                o<<endl;
            }
            return o;
        }
        Matrix operator + (const Matrix& m)
        {
            Matrix sum;
            for(int i=0;i<width;i++)
            for(int j=0;j<length;j++)
                sum.a[i][j]=a[i][j]+m.a[i][j];
            return sum;
        }
        ~Matrix(){fout<<"Destructor called"<<endl;}
}A,B;

int main()
{
    fout<<A+B<<endl;
    return 0;
}
//======================================

49  no match for 'operator<<' in 'fout << Matrix::operator+(const Matrix&)(((const Matrix&)((const Matrix*)(&B))))' 

//======================================
求指导~~~~

文章评论