Created
August 8, 2014 17:44
-
-
Save erynofwales/b19a23d2bcee58301f44 to your computer and use it in GitHub Desktop.
Matrix multiplication in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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