diff options
| author | Syndamia <kamen@syndamia.com> | 2024-05-10 10:10:21 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-05-10 10:10:21 +0300 |
| commit | 7b19cabee8b08478f31f6e4594ed28e1d04e153c (patch) | |
| tree | 3574b2c3fd75ab66701def640fe7476651236184 /week11/Exercise08/Link.cpp | |
| parent | 437e306dc9b79905105fb2e8af6dd1eae1b908ae (diff) | |
| download | oop-2023-solutions-7b19cabee8b08478f31f6e4594ed28e1d04e153c.tar oop-2023-solutions-7b19cabee8b08478f31f6e4594ed28e1d04e153c.tar.gz oop-2023-solutions-7b19cabee8b08478f31f6e4594ed28e1d04e153c.zip | |
[w11] Solved exercises
Diffstat (limited to 'week11/Exercise08/Link.cpp')
| -rw-r--r-- | week11/Exercise08/Link.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/week11/Exercise08/Link.cpp b/week11/Exercise08/Link.cpp new file mode 100644 index 0000000..d9941d5 --- /dev/null +++ b/week11/Exercise08/Link.cpp @@ -0,0 +1,54 @@ +#include "Link.h" +#include <cstring> + +void Link::free() { + delete[] textMessage; + delete[] address; +} + +void Link::copyFrom(const Link& other) { + this->address = new char[strlen(other.address) + 1]; + strcpy(this->address, other.address); +} + +Link::Link() : Message() { + this->address = nullptr; +} + +Link::~Link() { + free(); +} + +Link::Link(const Link& other) : Message(other) { + copyFrom(other); +} + +Link& Link::operator=(const Link& other) { + if (this != &other) { + Message::operator=(other); + free(); + copyFrom(other); + } + return *this; +} + +Link::Link(Link&& other) { + Message::operator=(std::move(other)); + this->address = other.address; + other.address = nullptr; +} + +Link& Link::operator=(Link&& other) { + if (this != &other) { + free(); + + Message::operator=(std::move(other)); + this->address = other.address; + other.address = nullptr; + } + return *this; +} + +unsigned Link::size() { + return (Length() + 1) + (strlen(address) + 1); +} |
