aboutsummaryrefslogtreecommitdiff
path: root/week10/Exercise08/Moderator.cpp
blob: 33ed63855c3e894e54e8fc495e57839565e1c1ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Moderator.h"
#include <cstring>
#include <iostream>

void Moderator::free() {
	delete[] signature;
}

void Moderator::copyFrom(const Moderator& other) {
	this->signature = new char[strlen(other.signature) + 1];
	strcpy(this->signature, other.signature);
}

Moderator::Moderator() : User() {
	signature = nullptr;
}

Moderator::~Moderator() {
	free();
}

Moderator::Moderator(const Moderator& other) : User(other) {
	copyFrom(other);
}

Moderator& Moderator::operator=(const Moderator& other) {
	if (this != &other) {
		User::operator=(other);
		free();
		copyFrom(other);
	}
	return *this;
}

Moderator::Moderator(Moderator&& other) : User(other) {
	this->signature = other.signature;
	other.signature = nullptr;
}

Moderator& Moderator::operator=(Moderator&& other) {
	if (this != &other) {
		free();
		User::operator=(std::move(other));

		this->signature = other.signature;
		other.signature = nullptr;
	}
	return *this;
}

const char* Moderator::GetSignature() {
	return this->signature;
}