// -*- coding: utf-8 -*- // Time-stamp: // Implementation of 2d m×n arrays with single array of size m×n #ifndef ARRAY2DD_H #define ARRAY2DD_H class Array2dd { public: // Constructors // Default constructor with no allocation Array2dd() : nlin(0), ncol(0), p(nullptr) {}; // Constructor from dimensions Array2dd(int m, int n); // Copy constructor Array2dd(const Array2dd& a); // Assignment operator Array2dd& operator=(const Array2dd& a); // Access operator to a non-constant array double& operator()(int i, int j); // Access operator to a constant array const double& operator()(int i, int j) const; // Destructor ~Array2dd() { free(); } private: // Alloc the array // + nlin and ncol must be valid void alloc(); // Free the array void free(); // Copy from another array // + nlin and ncol must be valid // + array must be allocated void copy(const double* t); int nlin; // Number of lines int ncol; // Number of columns // Unidimentional array containing all elements. // Element [i,j] is at position p[i*ncol+j] double* p; }; #endif