/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Array.tpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos creates an empty array // Construction with an unsigned int n as parameter // Consctrucion by copy and assignment operator // operator new [] to allocate memory // Access elements by operator [] // Exception if access index out of bounds // Function size template Array::Array() : data(NULL), _size(0) { // std::cout << "Default constructor called" << std::endl; } template Array::Array(unsigned int n) : _size(n) { data = new T[n]; } template Array::Array(const Array &other) : _size(other._size) { data = new T[other._size]; for (unsigned int i = 0;i < _size; i++) data[i] = other.data[i]; } template Array &Array::operator=(const Array &other) { if (this != &other) { delete[] data; _size = other._size; data = new T[_size]; for (unsigned int i = 0;i < _size; i++) data[i] = other.data[i]; } return (*this); } template Array::~Array() { delete[] data; } template T &Array::operator[](unsigned int i) { if (i >= _size) throw std::exception(); return (data[i]); } template unsigned int Array::size() const { return (_size); }