C++ 二进制表达式的操作数无效(同时使用两个重载运算符时)
我收到以下错误:C++ 二进制表达式的操作数无效(同时使用两个重载运算符时),c++,C++,我收到以下错误:错误:二进制表达式('std::ostream'(也称为'basic_ostream')和'Matrix')的操作数无效。 相关代码如下所示: Matrix Matrix::operator+(const Matrix &b){ Matrix C(r,c); int i,j; if(b.r!=r||b.c!=c) printf("invalid operation!"); else {for(i=0;i<r;i++)
错误:二进制表达式('std::ostream'(也称为'basic_ostream')和'Matrix')的操作数无效。
相关代码如下所示:
Matrix Matrix::operator+(const Matrix &b){
Matrix C(r,c);
int i,j;
if(b.r!=r||b.c!=c)
printf("invalid operation!");
else {for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
C.data[i][j]=data[i][j]+b.data[i][j];
}
cout<<endl;
}
}
return C;
}
ostream & operator<<(ostream &out, Matrix &A){
int i,j;
for(i=0;i<A.r;i++)
{
for(j=0;j<A.c;j++)
{
out<<setw(6)<<A.data[i][j];
}
cout<<endl;
}
return out;
}
矩阵::运算符+(常数矩阵和b){
矩阵C(r,C);
int i,j;
如果(b.r!=r | | b.c!=c)
printf(“无效操作!”);
else{for(i=0;i
此加法操作的结果是一个临时值
ostream & operator<<(ostream &out, Matrix &A){
ostream和操作符
Matrix C;
cout<<"A + B:"<<endl;
cout << C <<endl;
(A + B)
ostream & operator<<(ostream &out, Matrix &A){