Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class staticArray2D {
- private:
- const int w;
- const int h;
- T* memory;
- public:
- staticArray2D(const int width, const int height) : w(width) , h(height)
- {
- memory = new T[w*h];
- }
- ~staticArray2D() {
- delete [] memory;
- }
- const T get(int x, int y) const {
- return memory[x+y*h];
- }
- void set(int x,int y,T value) {
- memory[x+y*h] = value;
- }
- };
- int main() {
- staticArray2D<int> q(5,5);
- q.set(5,5,42);
- std::cout << q.get(5,5) << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement