I have a homework and my teacher told us to create a matrix class with templates.
One specification is, if you try to multiply two matrices with wrong dimensions,
like Matrix1[100][20] and Matrix2[20][101], the compiler needs to generate a error and not the runtime.
I haven’t started this part of the homework because I can’t imagine how the compiler will figure out that.
Sorry if that is a dummy question.
Thanks ppl.
The size of the matrix must be part of the type system, which implies that the dimensions must be passed as template arguments. Ie,
Matrx<100, 20>is a specific type.Now when you overload
operator*(), you can use a pair of template arguments to accept only matrices of the same size in the parameter list, like(Matrix<N, M> a, Matrix<N, M> b).