From b1b99275a70cf3daafeb203c490a06139d34d994 Mon Sep 17 00:00:00 2001 From: aortigos Date: Sun, 22 Mar 2026 21:41:58 +0100 Subject: [PATCH] ex02 done --- ex02/.build_start | 0 ex02/Array/Array.hpp | 2 ++ ex02/Array/Array.tpp | 38 +++++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 13 deletions(-) delete mode 100644 ex02/.build_start 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); }