fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T> class Matrix
  5. {
  6. public:
  7. Matrix(T *m,unsigned Y,unsigned X)
  8. {
  9. for(unsigned y=0;y<Y;++y,cout<<endl) for(unsigned x=0;x<X;++x) cout<<' '<<*(m++);
  10. cout<<endl;
  11. }
  12. template<unsigned Y,unsigned X>
  13. Matrix(T (&m)[Y][X])
  14. {
  15. for(unsigned y=0;y<Y;++y,cout<<endl) for(unsigned x=0;x<X;++x) cout<<' '<<m[y][x];
  16. cout<<endl;
  17. }
  18. };
  19.  
  20. int main()
  21. {
  22. double u[3][3]={{1,2,3},{4,5,6},{7,8,9}};
  23. Matrix<double> m((double*)u,sizeof(u)/sizeof(*u),sizeof(*u)/sizeof(**u));
  24. Matrix<double> M(u);
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
 1 2 3
 4 5 6
 7 8 9

 1 2 3
 4 5 6
 7 8 9