diff --git a/ex02/Array.hpp b/ex02/Array.hpp index 5ef147f..853f237 100644 --- a/ex02/Array.hpp +++ b/ex02/Array.hpp @@ -33,6 +33,15 @@ public: return _arr[pos]; } + T &operator[](const size_t &pos) const + { + if (pos < 0 || pos >= _size) + { + throw outOfBoundException(); + } + return _arr[pos]; + } + class outOfBoundException : public std::exception { virtual const char *what() const throw() { diff --git a/ex02/main.cpp b/ex02/main.cpp index b8f4f87..030284a 100644 --- a/ex02/main.cpp +++ b/ex02/main.cpp @@ -17,7 +17,8 @@ int main(int, char**) //SCOPE { Array tmp = numbers; - Array test(tmp); + const Array test(tmp); + std::cout << "accessing a const value : " << (int) test[15] << std::endl; } std::cout << "checking if values are the same after a copy..." << std::endl;