// -*- coding: utf-8 -*- // Time-stamp: // Class for arrays of floats // - Copy constructor and copy assignment and destructor #ifndef ARRAY_H #define ARRAY_H class Array { public: // Constructors // Default constructor: no allocation Array(); // Constructor from a size Array(int n); // Copy constructor Array(const Array& a); // Assignment operator Array& operator=(const Array& a); // Access operators // Access operator to non constant objets double& operator[](int i); // Access operator to constant objets const double& operator[](int i) const; // Destructor ~Array(); // Size int size() const { return length; } private: // Allocate dymanic array // + length must be valid void alloc(); // Free dynamic array void free(); // Copy values from t into the dynamic array // + length must be valid // + p must valid: dynamic array already allocated void copy(double* t); int length; // Size of the dynamic array double *p; // Address of the dynamic array or nullptr if none }; #endif