// -*- coding: utf-8 -*- // Time-stamp: // Implementation of 2d m×n arrays with single array of size m×n #ifndef ARRAY2DD_H #define ARRAY2DD_H #include "array2d.hpp" class Array2dd : public Array2d { public: // Constructors // Default constructor with no allocation Array2dd() : Array2d(0,0), p(nullptr) {}; // Constructor from dimensions Array2dd(int m, int n); // Copy constructor Array2dd(const Array2dd& a); // Assignment operator // This declaration is ncessary in order to inherit the // assigment operator of the class Array2d. Otherwise, the // compile generates a default assigment operator // Array2dd& operator=(const Array2dd& a) using Array2d::operator=; // Access operator to a non-constant array virtual Line operator[](int i) override { return Line(p + i * ncol, ncol); } // Access operator to a constant array virtual const Line operator[](int i) const override { return Line(p + i * ncol, ncol); } // Destructor ~Array2dd() { free(); } private: // Alloc the array // + nlin and ncol must be valid virtual void alloc() override; // Free the array virtual void free() override; // Copy from another array // + nlin and ncol must be valid // + array must be allocated void copy(const double* t); // Unidimentional array containing all elements. // Element [i,j] is at position p[i*ncol+j] double* p; }; #endif