我想重载*运算符有两个目的:对于多操作数重载运算符*
第一个目的:
m4 * 3.5; //m4 is a matrix object
上述作品具有这种功能,绝对没有在这里实施
问题Matrix operator *(const double n)
然而,当我试图反向,即
3.5 * m4;
我得到一个错误,说没有匹配的函数。所以,我对这种特殊情况下作出这一功能
Matrix operator *(const double n, Matrix &obj)
{
for(unsigned int i = 0; i < rows; i++)
{
for(unsigned int j = 0; j < cols; j++)
{
obj[i][j] = obj[i][j] * n;
}
}
return *this;
}
现在,我得到的错误:
error: ‘Matrix Matrix::operator*(double, Matrix&)’ must take either zero or one argument Matrix operator *(const double n, Matrix &obj);
error: no match for ‘operator*’ (operand types are ‘double’ and ‘Matrix’)
cout << 3.5 * m4 << endl;
我不知道如何克服操作数的问题!
不幸的是我不能使用BLAS,Eigen之类的东西。这项任务要求我们努力通过这个矩阵废话。
请不要编辑我的帖子只是为了纠正我的语法和不正确的大写。我在这里为编程帮助而不是英语课。这些错误并不妨碍任何人理解我的代码的能力! – Jaydie