// For left scaler
Matrix operator*(int x , Matrix &m)
{
Matrix Mul(m.get_rows(),m.get_cols());
int **mul=Mul.get_matrix();
int **mat = m.get_matrix();
for (int i = 0; i < m.get_rows(); i++)
for (int j = 0; j < m.get_cols(); j++)
mul[i][j] = x * mat[i][j];
return Mul;
}
// For right scaler
Matrix operator*(Matrix &m ,int x)
{
Matrix Mul(m.get_rows(),m.get_cols());
int **mul=Mul.get_matrix();
int **mat = m.get_matrix();
for (int i = 0; i < m.get_rows(); i++)
for (int j = 0; j < m.get_cols(); j++)
mul[i][j] = x * mat[i][j];
return Mul;
}
Above is the code that multiply scaller with a matrix, there are two satiuations, the first one is scaller with the right (matrix * 5), the second one is scaller with the left (5 * matrix). Both the operator functions are overloaded for the perpuse,and they just works well, when i use them like so
//scaler to the left
result = 5 * m1;
cout << result;
//scaler to the right
result = m1 * 2;
cout << result;
The question is the code in both the operator functions are excatly the same, so is there any better way to do this, in order to reuse the code.