I have a matrix class defined this way:
template<int M, int N, typename T>
class Matrix
{
typedef Matrix<M, N, T> MTYPE;
/*...*/
};
I have to implement the matrix multiplication but I do not know how to do the operator overriding..
Something like
MTYPE operator *(MTYPE& m) { /*...*/ }
Would accept only a N*M matrix. So how can I overcome this problem?
As has been pointed out in a comment, *= doesn’t make sense for non-square matrices.
For the general case,
Or, if you prefer, use a free function operator* with two parameters (and template arguments M,N,L, and T), and make it a friend of your matrix class.