aboutsummaryrefslogtreecommitdiff
path: root/week11/Exercise02/Manager.cpp
blob: c7ae6ffc37d66bdeb75bd207dcfe285b777eb53d (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
#include "Manager.h"

void Manager::free() {
	delete[] managedTeam;
}

void Manager::copyFrom(const Manager& other) {
	this->length = other.length;
	this->managedTeam = new Employee[other.length + 1];
	for (int i = 0; i < length; i++) {
		this->managedTeam[i] = other.managedTeam[i];
	}
}

Manager::Manager() {
	this->managedTeam = nullptr;
	this->length = 0;
}

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

Manager::Manager(const Manager& other) {
	copyFrom(other);
}

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

Manager::Manager(Manager&& other) {
	this->length = other.length;
	this->managedTeam = other.managedTeam;
	other.managedTeam = nullptr;
}

Manager& Manager::operator=(Manager&& other) {
	if (this != &other) {
		free();

		this->length = other.length;
		this->managedTeam = other.managedTeam;
		other.managedTeam = nullptr;
	}
	return *this;
}