Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. template <class T>
  2. class staticArray2D {
  3.     private:
  4.     const int w;
  5.     const int h;
  6.     T* memory;
  7.    
  8.     public:
  9.    
  10.     staticArray2D(const int width, const int height) : w(width) , h(height)
  11.     {
  12.         memory = new T[w*h];
  13.     }    
  14.     ~staticArray2D() {
  15.         delete [] memory;
  16.     }
  17.     const T get(int x, int y) const {
  18.         return memory[x+y*h];
  19.     }
  20.     void set(int x,int y,T value) {
  21.         memory[x+y*h] = value;
  22.     }
  23. };
  24.  
  25. int main() {
  26.   staticArray2D<int> q(5,5);
  27.   q.set(5,5,42);
  28.   std::cout << q.get(5,5) << "\n";
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement