c++矩阵加法运算符的重载

2025-02-23 15:24:45
推荐回答(1个)
回答1:

运算符重载不是你这么玩的,运算符重载是自身与other做运算,函数参数只要一个other就可以了:
Matrix Matrix::operator + (const Matrix& other)
{
int r=other.row,c=other.col;
Matrix c1(r,c);
for(int i=0;i{ c1.p[i]=this->p[i]+other.p[i];}
return c1;
}