aboutsummaryrefslogtreecommitdiff
path: root/week12/Exercise3/TelecommunicationCompany.cpp
diff options
context:
space:
mode:
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;