// -*- coding: utf-8 -*- // Time-stamp: // Implementation of 2d m×n arrays with an array for each line #ifndef ARRAY2DI_H #define ARRAY2DI_H #include "array2d.hpp" class Array2di : public Array2d { public: // Constructors // Default constructor with no allocation Array2di() : Array2d(0, 0), p(nullptr) {}; // Constructor from dimensions Array2di(int m, int n); // Constructor from dimensions and a value for initialization Array2di(int m, int n, double v); // Copy constructor Array2di(const Array2di& 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 Line operator[](int i) { return Line(p[i], ncol); } // Access operator to a constant array const Line operator[](int i) const { return Line(p[i], ncol); } // Destructor ~Array2di() { free(); } private: // Alloc the array virtual void alloc() override; // Free the array virtual void free() override; // Copy from another array // + nlin and ncol must be valid // + arrays must be allocated void copy(double** t); // Array of pointers // Each p[i] contains a pointer to the array for line i. double** p; }; #endif