#pragma once template class TwoArray { T* first; U* second; unsigned allocated; unsigned size; void free(); void copyFrom(const TwoArray& other); public: TwoArray(); ~TwoArray(); TwoArray(const TwoArray& other); TwoArray& operator=(const TwoArray& other); TwoArray(TwoArray&& other); TwoArray& operator=(TwoArray&& other); T& operator[](int index); const T& operator[](int index) const; U& operator()(int index); const U& operator()(int index) const; }; template void TwoArray::free() { delete[] first; delete[] second; } template void TwoArray::copyFrom(const TwoArray& other) { this->size = other.size; this->allocated = other.allocated; first = new T[allocated]; second = new U[allocated]; for (int i = 0; i < size; i++) { first[i] = other.first[i]; second[i] = other.second[i]; } } template TwoArray::TwoArray() { first = second = nullptr; size = allocated = 0; } template TwoArray::~TwoArray() { free(); } template TwoArray::TwoArray(const TwoArray& other) { copyFrom(other); } template TwoArray& TwoArray::operator=(const TwoArray& other) { if (this != &other) { free(); copyFrom(other); } return *this; } template TwoArray::TwoArray(TwoArray&& other) { this->first = other.first; other.first = nullptr; this->second = other.second; other.second = nullptr; this->allocated = other.allocated; this->size = other.size; } template TwoArray& TwoArray::operator=(TwoArray&& other) { if (this != &other) { free(); this->first = other.first; other.first = nullptr; this->second = other.second; other.second = nullptr; this->allocated = other.allocated; this->size = other.size; } return *this; } template T& TwoArray::operator[](int index) { if (index < 0 || index >= size) throw "Invalid index!"; return first[index]; } template const T& TwoArray::operator[](int index) const { if (index < 0 || index >= size) throw "Invalid index!"; return first[index]; } template U& TwoArray::operator()(int index) { if (index < 0 || index >= size) throw "Invalid index!"; return second[index]; } template const U& TwoArray::operator()(int index) const { if (index < 0 || index >= size) throw "Invalid index!"; return second[index]; }