Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. template<unsigned int rows, unsigned int cols>
  2. class Matrix
  3. {
  4. // Protected/private means that you cannot access
  5. // this names from outside the class
  6. protected:
  7. //////////////////////////////////////////////////
  8. // Class fields
  9. //////////////////////////////////////////////////
  10.  
  11. /// Matrix data as STATIC array
  12. double data[rows * cols];
  13.  
  14. public:
  15. // Constructors are executed when you create
  16. // a new variable of type Matrix
  17.  
  18. /**
  19. * Default constructor, doesn't do anything
  20. */
  21. Matrix()
  22. {
  23. //
  24. }
  25.  
  26. /**
  27. * Returns number of columns
  28. */
  29. unsigned int numRows() const
  30. {
  31. return rows;
  32. }
  33.  
  34. /**
  35. * Returns number of columns
  36. */
  37. unsigned int numCols() const
  38. {
  39. return cols;
  40. }
  41.  
  42. /**
  43. * Custom subscript operator, returns address of
  44. * first element of i-th row
  45. */
  46. double * operator[](unsigned int i)
  47. {
  48. return data + (i * cols);
  49. }
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement