ex02 fixed

This commit is contained in:
Angel Ortigosa Perez
2026-04-08 20:51:29 +02:00
parent ceae775295
commit 317ecbc1f9
3 changed files with 46 additions and 47 deletions

View File

@@ -64,9 +64,9 @@ Array<T>::Array(unsigned int n) : length(n)
}
template <typename T>
T &Array<T>::operator[](unsigned int n)
T &Array<T>::operator[](int n)
{
if (n >= length)
if (n < 0 || (unsigned int)n >= length)
throw std::exception();
return (data[n]);
}