aboutsummaryrefslogtreecommitdiff
path: root/week10/Exercise08/Moderator.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-05-08 10:07:57 +0300
committerSyndamia <kamen@syndamia.com>2024-05-08 10:07:57 +0300
commit75cff007b4896eed49b758be0959668673ae1bf3 (patch)
tree6af017d6047c78bce05af166fdbe85cae40692b5 /week10/Exercise08/Moderator.cpp
parent6dd52a7c9d8db3e8b14494ae99e8b9f3b76d1262 (diff)
downloadoop-2023-solutions-75cff007b4896eed49b758be0959668673ae1bf3.tar
oop-2023-solutions-75cff007b4896eed49b758be0959668673ae1bf3.tar.gz
oop-2023-solutions-75cff007b4896eed49b758be0959668673ae1bf3.zip
[w10] Fixed mistakes in certain exercises
Diffstat (limited to 'week10/Exercise08/Moderator.cpp')
-rw-r--r--week10/Exercise08/Moderator.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/week10/Exercise08/Moderator.cpp b/week10/Exercise08/Moderator.cpp
index d5d53b8..33ed638 100644
--- a/week10/Exercise08/Moderator.cpp
+++ b/week10/Exercise08/Moderator.cpp
@@ -1,13 +1,12 @@
#include "Moderator.h"
#include <cstring>
+#include <iostream>
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);
}
@@ -17,38 +16,32 @@ Moderator::Moderator() : User() {
}
Moderator::~Moderator() {
- Moderator::free();
+ free();
}
-Moderator::Moderator(const Moderator& other) {
- Moderator::copyFrom(other);
+Moderator::Moderator(const Moderator& other) : User(other) {
+ copyFrom(other);
}
Moderator& Moderator::operator=(const Moderator& other) {
if (this != &other) {
- Moderator::free();
- Moderator::copyFrom(other);
+ User::operator=(other);
+ free();
+ copyFrom(other);
}
return *this;
}
-Moderator::Moderator(Moderator&& other) {
- this->name = other.name;
- other.name = nullptr;
- this->password = other.password;
- other.password = nullptr;
+Moderator::Moderator(Moderator&& other) : User(other) {
this->signature = other.signature;
other.signature = nullptr;
}
Moderator& Moderator::operator=(Moderator&& other) {
if (this != &other) {
- Moderator::free();
+ free();
+ User::operator=(std::move(other));
- this->name = other.name;
- other.name = nullptr;
- this->password = other.password;
- other.password = nullptr;
this->signature = other.signature;
other.signature = nullptr;
}