Skip to content

Instantly share code, notes, and snippets.

@erynofwales
Created August 8, 2014 17:44
Show Gist options
  • Save erynofwales/b19a23d2bcee58301f44 to your computer and use it in GitHub Desktop.
Save erynofwales/b19a23d2bcee58301f44 to your computer and use it in GitHub Desktop.
Matrix multiplication in C++
#include <cstdio>
template<unsigned int N, unsigned int M>
struct Matrix
{
static const unsigned int sRows = N;
static const unsigned int sCols = M;
template <unsigned int P>
Matrix<N, P>
operator*(Matrix<M, P> lhs)
{
return Matrix<N, P>();
}
private:
double mData[sRows * sCols];
};
int
main(int argc,
const char *argv[])
{
Matrix<4, 1> m14;
printf("Matrix<1, 4> sRows = %u, sCols = %u\n", Matrix<1, 4>::sRows, Matrix<1, 4>::sCols);
Matrix<4, 4> m44;
printf("Matrix<4, 4> sRows = %u, sCols = %u\n", Matrix<4, 4>::sRows, Matrix<4, 4>::sCols);
Matrix<4, 1> p = m44 * m14;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment