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/Exercise05/Counted.hpp | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 week11/Exercise05/Counted.hpp (limited to 'week11/Exercise05/Counted.hpp') diff --git a/week11/Exercise05/Counted.hpp b/week11/Exercise05/Counted.hpp new file mode 100644 index 0000000..fe705ab --- /dev/null +++ b/week11/Exercise05/Counted.hpp @@ -0,0 +1,64 @@ +#pragma once + +template +class Counted { + T elem; + unsigned count; + +public: + T& GetElem(); + unsigned GetCount(); + + Counted& operator++(); + Counted operator++(int); + Counted& operator--(); + Counted operator--(int); + Counted& operator+=(int countChange); + Counted& operator-=(int countChange); +}; + +template +T& Counted::GetElem() { + return elem; +} + +template +unsigned Counted::GetCount() { + return count; +} + +template +Counted& Counted::operator++() { + ++count; + return *this; +} + +template +Counted Counted::operator++(int) { + count++; + return *this; +} + +template +Counted& Counted::operator--() { + --count; + return *this; +} + +template +Counted Counted::operator--(int) { + count--; + return *this; +} + +template +Counted& Counted::operator+=(int countChange) { + count += countChange; + return *this; +} + +template +Counted& Counted::operator-=(int countChange) { + count -= countChange; + return *this; +} -- cgit v1.2.3