diff --git a/ex02/.build_start b/ex02/.build_start deleted file mode 100644 index e69de29..0000000 diff --git a/ex02/Array/Array.hpp b/ex02/Array/Array.hpp index dc69368..d360d77 100644 --- a/ex02/Array/Array.hpp +++ b/ex02/Array/Array.hpp @@ -15,6 +15,8 @@ # define ARRAY_HPP # include +# include +# include template class Array diff --git a/ex02/Array/Array.tpp b/ex02/Array/Array.tpp index 7c887ce..f86ac17 100644 --- a/ex02/Array/Array.tpp +++ b/ex02/Array/Array.tpp @@ -6,7 +6,7 @@ /* By: aortigos ::Array() : data(NULL), _size(0) } template -Array::Array(unsigned int n) +Array::Array(unsigned int n) : _size(n) { - + data = new T[n]; } template -Array(const Array &other) +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 &operator=(const Array &other) +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::~Array() { - + delete[] data; } template -T &operator[](unsigned int i) +T &Array::operator[](unsigned int i) { - + if (i >= _size) + throw std::exception(); + return (data[i]); } template -unsigned int size() const +unsigned int Array::size() const { - + return (_size); }