I'm doing a course project and I created a matrix class with 2d vector in cpp. I'm trying to override * operator to an global operator with the matrix obj.
this is my declaration:
friend Matrix<T> operator * (T t, const Matrix<T> &m);
and this is the function:
template <typename T>
Matrix<T> operator * (T t, const Matrix<T> &m)
{
int i, j;
Matrix<T> ans(rows, cols);
for (i = 0; i < rows; i++)
{
for (j = 0; j < rows; j++)
{
ans[i][j] = t * m.mat[i][j];
}
}
return ans;
}
my error is: error C2244: 'Matrix::operator *' : unable to match function definition to an existing declaration
what is wrong with my code??