From 77b020ac187205c808e667564fdc816ff4066d24 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 10 May 2022 20:17:16 +0300 Subject: Update Optional.hpp --- Sem. 10/Examples/Optional/Optional.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sem. 10/Examples/Optional/Optional.hpp b/Sem. 10/Examples/Optional/Optional.hpp index 9e3ab0f..147d8e5 100644 --- a/Sem. 10/Examples/Optional/Optional.hpp +++ b/Sem. 10/Examples/Optional/Optional.hpp @@ -12,6 +12,9 @@ public: Optional(); Optional(const T& obj); + Optional(const Optional& other); + Optional operator=(const Optional& other); + bool containsData() const; const T& getData() const; void setData(const T& el); @@ -72,3 +75,22 @@ void Optional::clear() free(); data = nullptr; } + + +template +Optional::Optional(const Optional& other) +{ + copyFrom(other); +} + + +template +Optional Optional::operator=(const Optional& other) +{ + if (this != &other) + { + free(); + copyFrom(other); + } + return *this; +} -- cgit v1.3.1-23-gd82d