fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class Matrix
  6. {
  7. T ** matrix;
  8. unsigned height;
  9. unsigned width;
  10. public:
  11. Matrix(unsigned _width, unsigned _height) : height(_height), width(_width)
  12. {
  13. matrix = new T * [height];
  14.  
  15. for(int i = 0; i < height; ++i) {
  16. matrix[i] = new T [width];
  17. }
  18. }
  19.  
  20. ~Matrix()
  21. {
  22. for(int i = 0; i < height; ++i) {
  23. delete [] matrix[i];
  24. }
  25.  
  26. delete [] matrix;
  27. }
  28.  
  29. //zmodyfikuj sobie zeby Ci ladnie sprawdzalo czy poza zakres nie wychodzisz
  30. T * operator[](unsigned index)
  31. {
  32. return matrix[index];
  33. }
  34.  
  35. };
  36.  
  37.  
  38. int main() {
  39. Matrix <int> mat(5,6);
  40. mat[2][2] = 10;
  41. cout<<mat[2][2];
  42.  
  43. // your code goes here
  44. return 0;
  45. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
10