I have matrix class and overloaded operator + working with other matrices and scalars. When I try to use it like mat2=mat+3; that works ok but if i change scalar and matrix mat2=3+mat; it says "Invalid operands to binary expression('int' and Matrix<3, 4>')" (3,4 is rows and columns in this matrix). How I understand I haven't overloaded + for this cases but I don't find how to overload it
Matrix operator+(const T &a) {
Matrix<row, col, T> result;
for (int i = 0; i < row; ++i) {
for (int j = 0; j < col; ++j) {
result.elements[i][j] = elements[i][j] + a;
}
}
return result;
}