diff --git a/ex00/whatever.hpp b/ex00/whatever.hpp index 3d5cf99..7f6be55 100644 --- a/ex00/whatever.hpp +++ b/ex00/whatever.hpp @@ -19,9 +19,8 @@ template void swap(T &a, T &b) { - T tmp; + T tmp = a; - tmp = a; a = b; b = tmp; } diff --git a/ex02/Array/Array.hpp b/ex02/Array/Array.hpp index d360d77..dc25ef2 100644 --- a/ex02/Array/Array.hpp +++ b/ex02/Array/Array.hpp @@ -32,7 +32,8 @@ class Array Array &operator=(const Array &other); ~Array(); - T &operator[](unsigned int i); + T &operator[](unsigned int i); + T const &operator[](unsigned int i) const; unsigned int size() const; }; diff --git a/ex02/Array/Array.tpp b/ex02/Array/Array.tpp index 123a33a..5013436 100644 --- a/ex02/Array/Array.tpp +++ b/ex02/Array/Array.tpp @@ -58,6 +58,14 @@ T &Array::operator[](unsigned int i) return (data[i]); } +template +T const &Array::operator[](unsigned int i) const +{ + if (i >= _size) + throw std::exception(); + return (data[i]); +} + template unsigned int Array::size() const {