I'm trying to learn templates by writing some linear algebra code. I have created a vector template
template<class T, int N>
class Vektor {
T entry[N];
etc...
and then a matrix template that consists of column vectors:
template <class T, int N, int M>
class Matrix {
Vektor<T,N> column[M];
etc...
My problem is overloading the multiplication operator to define matrix multiplication. Seems I would need something to the effect of
Matrix<T,N,K> Matrix<T,N,M>:: operator*(const Matrix<T,M,K>& B) etc...
given that the matrices are often of different sizes. Putting this in the template definition doesn't work because of the extra K parameter. Defining it in a whole new template of the form
template<class T, int N, int M, int K>
Matrix<T,N,K> Matrix<T,N,M>:: operator*(const Matrix<T,M,K>& B) etc..
doesn't work because this operator wasn't defined in the original matrix class. Seems like a an elemntary issue, but I can't decipher the literature I have on this subject.
Many thanks, David
template<class T, int N>
class Vektor {
T entry[N];
etc...
and then a matrix template that consists of column vectors:
template <class T, int N, int M>
class Matrix {
Vektor<T,N> column[M];
etc...
My problem is overloading the multiplication operator to define matrix multiplication. Seems I would need something to the effect of
Matrix<T,N,K> Matrix<T,N,M>:: operator*(const Matrix<T,M,K>& B) etc...
given that the matrices are often of different sizes. Putting this in the template definition doesn't work because of the extra K parameter. Defining it in a whole new template of the form
template<class T, int N, int M, int K>
Matrix<T,N,K> Matrix<T,N,M>:: operator*(const Matrix<T,M,K>& B) etc..
doesn't work because this operator wasn't defined in the original matrix class. Seems like a an elemntary issue, but I can't decipher the literature I have on this subject.
Many thanks, David