diff options
| author | Syndamia <kamen@syndamia.com> | 2024-05-07 22:17:12 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-05-07 22:17:12 +0300 |
| commit | 88f15e35713c9632216931d26443dc588238732f (patch) | |
| tree | 147ff8c72009afc58d3eabb1c026a33b798f20fe /week10/Exercise08/Moderator.cpp | |
| parent | f4642325f58172e85b9e41e35f69e8bea46f78c6 (diff) | |
| download | oop-2023-solutions-88f15e35713c9632216931d26443dc588238732f.tar oop-2023-solutions-88f15e35713c9632216931d26443dc588238732f.tar.gz oop-2023-solutions-88f15e35713c9632216931d26443dc588238732f.zip | |
[w10] Added rough solutions to ex 1-10
Diffstat (limited to 'week10/Exercise08/Moderator.cpp')
| -rw-r--r-- | week10/Exercise08/Moderator.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/week10/Exercise08/Moderator.cpp b/week10/Exercise08/Moderator.cpp new file mode 100644 index 0000000..d5d53b8 --- /dev/null +++ b/week10/Exercise08/Moderator.cpp @@ -0,0 +1,60 @@ +#include "Moderator.h" +#include <cstring> + +void Moderator::free() { + User::free(); + delete[] signature; +} + +void Moderator::copyFrom(const Moderator& other) { + User::copyFrom(other); + this->signature = new char[strlen(other.signature) + 1]; + strcpy(this->signature, other.signature); +} + +Moderator::Moderator() : User() { + signature = nullptr; +} + +Moderator::~Moderator() { + Moderator::free(); +} + +Moderator::Moderator(const Moderator& other) { + Moderator::copyFrom(other); +} + +Moderator& Moderator::operator=(const Moderator& other) { + if (this != &other) { + Moderator::free(); + Moderator::copyFrom(other); + } + return *this; +} + +Moderator::Moderator(Moderator&& other) { + this->name = other.name; + other.name = nullptr; + this->password = other.password; + other.password = nullptr; + this->signature = other.signature; + other.signature = nullptr; +} + +Moderator& Moderator::operator=(Moderator&& other) { + if (this != &other) { + Moderator::free(); + + this->name = other.name; + other.name = nullptr; + this->password = other.password; + other.password = nullptr; + this->signature = other.signature; + other.signature = nullptr; + } + return *this; +} + +const char* Moderator::GetSignature() { + return this->signature; +} |
