Usually having commutativity by default on an operator would be undesirable, not to mention hard to implement in an intuitive way for a language, so you have to define both.
You'd need to use a global operator for one of the two cases, but it's easy enough to map that global operator on the existing one for the commutative case:
You have to give argument values names to use them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
struct Matrix
{
// This is the (Matrix * scalar) operator
Matrix operator * ( double k ) const
{
Matrix m;
/* multiply your matrix (*this) by the scalar (k) here and put the result in m*/
return m;
}
};
// This is the (scalar * Matrix) operator
Matrix operator * ( double k, const Matrix& m )
{
return m * k;
}