diff options
Update Optional.hpp
1 files changed, 22 insertions, 0 deletions
| -rw-r--r-- | Sem. 10/Examples/Optional/Optional.hpp | 22 |
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<T>& other); + Optional<T> operator=(const Optional<T>& other); + bool containsData() const; const T& getData() const; void setData(const T& el); @@ -72,3 +75,22 @@ void Optional<T>::clear() free(); data = nullptr; } + + +template <typename T> +Optional<T>::Optional(const Optional<T>& other) +{ + copyFrom(other); +} + + +template <typename T> +Optional<T> Optional<T>::operator=(const Optional<T>& other) +{ + if (this != &other) + { + free(); + copyFrom(other); + } + return *this; +} |
