From 7b19cabee8b08478f31f6e4594ed28e1d04e153c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 10 May 2024 10:10:21 +0300 Subject: [w11] Solved exercises --- week11/Exercise08/Link.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 week11/Exercise08/Link.cpp (limited to 'week11/Exercise08/Link.cpp') 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 + +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); +} -- cgit v1.2.3