fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class matrix
  6. {
  7. private:
  8. unsigned m_height,m_width;
  9. double *m_data;
  10. public:
  11. matrix(unsigned height=0,unsigned width=0):m_height(height),m_width(width),m_data(new double[height*width])
  12. {
  13. memset(m_data,0,height*width);
  14. }
  15. unsigned height()const { return m_height; }
  16. unsigned width()const { return m_width; }
  17. double *operator[](unsigned y) { return m_data+y*m_width; }
  18. const double *operator[](unsigned y)const { return m_data+y*m_width; }
  19. friend ostream &operator<<(ostream &s,const matrix m)
  20. {
  21. for(unsigned y=0;y<m.height();++y,s<<endl) for(unsigned x=0;x<m.width();++x) s<<m[y][x]<<'\t';
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. matrix m(3,3);
  28. m[1][1]=3;
  29. cout<<m;
  30. return 0;
  31. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0	0	0	
0	3	0	
0	0	0