aboutsummaryrefslogtreecommitdiff
path: root/week12/Exercise3/TelecommunicationCompany.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-05-10 16:15:49 +0300
committerSyndamia <kamen@syndamia.com>2024-05-10 16:15:49 +0300
commit3e6537ee27aa23e9cb507d72c27d1d48d2c043d6 (patch)
treea84cb0abb0f9515b86c6215b3bd8ab74f2367c67 /week12/Exercise3/TelecommunicationCompany.cpp
parent2d5f9c3b7cd56d5fdb5b7642b43cd5e166b5462e (diff)
downloadoop-2023-solutions-3e6537ee27aa23e9cb507d72c27d1d48d2c043d6.tar
oop-2023-solutions-3e6537ee27aa23e9cb507d72c27d1d48d2c043d6.tar.gz
oop-2023-solutions-3e6537ee27aa23e9cb507d72c27d1d48d2c043d6.zip
[w12] Added TelecommunicationCompany copying
Diffstat (limited to 'week12/Exercise3/TelecommunicationCompany.cpp')
-rw-r--r--week12/Exercise3/TelecommunicationCompany.cpp22
1 files changed, 22 insertions, 0 deletions
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;