There are several serious issues in your code.
The largest of them: double[10][10] not convertible to pointer double** .
You also have a memory leak ( mat ) in your transposeMatrix() implementation.
I recommend separating matrix printing and matrix transfer issues. Perhaps separate methods on a (template) matrix class.
And now, saying that ...
Why write when an excellent implementation already exists ?
Example:
#include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; matrix<double> m(3, 3); for (unsigned i = 0; i < m.size1(); ++i) { for (unsigned j = 0; j < m.size2(); ++j) { m(i, j) = 3 * i + j; } } std::cout << m << std::endl; std::cout << trans(m) << std::endl; }
Output:
[3,3]((0,1,2),(3,4,5),(6,7,8)) [3,3]((0,3,6),(1,4,7),(2,5,8))
source share