This commit is contained in:
aortigos
2026-03-23 09:56:09 +01:00
parent 8c6a50b16f
commit 582f5ad276
3 changed files with 11 additions and 3 deletions

View File

@@ -19,9 +19,8 @@
template <typename T> template <typename T>
void swap(T &a, T &b) void swap(T &a, T &b)
{ {
T tmp; T tmp = a;
tmp = a;
a = b; a = b;
b = tmp; b = tmp;
} }

View File

@@ -32,7 +32,8 @@ class Array
Array &operator=(const Array &other); Array &operator=(const Array &other);
~Array(); ~Array();
T &operator[](unsigned int i); T &operator[](unsigned int i);
T const &operator[](unsigned int i) const;
unsigned int size() const; unsigned int size() const;
}; };

View File

@@ -58,6 +58,14 @@ T &Array<T>::operator[](unsigned int i)
return (data[i]); return (data[i]);
} }
template <typename T>
T const &Array<T>::operator[](unsigned int i) const
{
if (i >= _size)
throw std::exception();
return (data[i]);
}
template <typename T> template <typename T>
unsigned int Array<T>::size() const unsigned int Array<T>::size() const
{ {