Advertisement
NachoMan

vector2d

Aug 10th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. template <class T>
  2. class vector2D
  3. {
  4.     std::vector<T> m_Field;
  5.     int m_Height;
  6.     int m_Width;
  7. public:
  8.     int getWidth() const{return m_Width;}
  9.     int getHeight() const{return m_Height;}
  10.  
  11.     vector2D()
  12.         :m_Field(),
  13.         m_Height(0),
  14.         m_Width(0)
  15.     {
  16.     }
  17.  
  18.     vector2D(int width, int height)
  19.         :m_Field(width*height),
  20.         m_Height(width),
  21.         m_Width(height)
  22.     {
  23.     }
  24.  
  25.     void resize(int width, int height)
  26.     {
  27.         m_Width = width;
  28.         m_Height = height;
  29.         m_Field.resize(m_Width*m_Height)
  30.     }
  31.  
  32.     T& at(int x, int y)
  33.     {
  34.         return m_Field.at(m_Width*vector.y+vector.x);
  35.     }
  36.  
  37.     const T& at(int x, int y) const
  38.     {
  39.         return m_Field.at(m_Width*vector.y+vector.x);
  40.     }
  41. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement