#pragma once #include #include template class Array { public: Array(); Array(unsigned int size); Array(const Array& other); Array& operator=(const Array& other); T& operator[](unsigned int index); const T& operator[](unsigned int index) const; unsigned int size() const; ~Array(); private: T* data; unsigned int _size; }; template Array::Array(): data(NULL), _size(0) { } template Array::Array(unsigned int size): data(new T[size]()), _size(size) { } template Array::Array(const Array& other): data(new T[other._size]), _size(other._size) { for (unsigned int i = 0; i < _size; ++i) data[i] = other.data[i]; } template Array& Array::operator=(const Array& other) { if (this == &other) return *this; delete[] data; data = new T[other._size]; _size = other._size; for (unsigned int i = 0; i < _size; ++i) data[i] = other.data[i]; return *this; } template T& Array::operator[](unsigned int index) { if (index >= _size) throw std::out_of_range("Array index out of range"); return data[index]; } template const T& Array::operator[](unsigned int index) const { if (index >= _size) throw std::out_of_range("Array index out of range"); return data[index]; } template unsigned int Array::size() const { return _size; } template Array::~Array() { delete[] data; }