From 3e6537ee27aa23e9cb507d72c27d1d48d2c043d6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 10 May 2024 16:15:49 +0300 Subject: [w12] Added TelecommunicationCompany copying --- week12/Exercise3/TelecommunicationCompany.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'week12/Exercise3/TelecommunicationCompany.cpp') diff --git a/week12/Exercise3/TelecommunicationCompany.cpp b/week12/Exercise3/TelecommunicationCompany.cpp index 7b877ca..34987a4 100644 --- a/week12/Exercise3/TelecommunicationCompany.cpp +++ b/week12/Exercise3/TelecommunicationCompany.cpp @@ -1,5 +1,6 @@ #include "TelecommunicationCompany.h" #include "MobileDevice.h" +#include "Telephone.h" void TelecommunicationCompany::resize() { allocated *= 2; @@ -18,6 +19,15 @@ void TelecommunicationCompany::free() { delete[] devices; } +void TelecommunicationCompany::copyFrom(const TelecommunicationCompany& other) { + this->allocated = other.allocated; + this->size = other.size; + this->devices = new MobileDevice*[size]; + for (int i = 0; i < size; i++) { + this->devices[i] = other.devices[i]->clone(); + } +} + TelecommunicationCompany::TelecommunicationCompany() { devices = nullptr; allocated = size = 0; @@ -27,6 +37,18 @@ TelecommunicationCompany::~TelecommunicationCompany() { free(); } +TelecommunicationCompany::TelecommunicationCompany(const TelecommunicationCompany& other) { + copyFrom(other); +} + +TelecommunicationCompany& TelecommunicationCompany::operator=(const TelecommunicationCompany& other) { + if (this != &other) { + copyFrom(other); + free(); + } + return *this; +} + TelecommunicationCompany::TelecommunicationCompany(TelecommunicationCompany&& other) { this->size = other.size; this->allocated = other.allocated; -- cgit v1.2.3