From 5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf Mon Sep 17 00:00:00 2001 From: angeld55 Date: Tue, 10 May 2022 20:06:53 +0300 Subject: sem 11 --- Sem. 10/Examples/Pair/Pair.hpp | 43 +++++++++++++++++++++++++++++++++++++++ Sem. 10/Examples/Pair/Source2.cpp | 14 +++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Sem. 10/Examples/Pair/Pair.hpp create mode 100644 Sem. 10/Examples/Pair/Source2.cpp (limited to 'Sem. 10/Examples/Pair') diff --git a/Sem. 10/Examples/Pair/Pair.hpp b/Sem. 10/Examples/Pair/Pair.hpp new file mode 100644 index 0000000..adf16b7 --- /dev/null +++ b/Sem. 10/Examples/Pair/Pair.hpp @@ -0,0 +1,43 @@ +#pragma once + +template +class Pair +{ + T first; + D second; +public: + Pair() = default; + Pair(const T& first, const D& second); + const T& getFirst() const; + const D& getSecond() const; + + void setFirst(const T& newValue); + void setSecond(const D& newValue); +}; + +template +Pair::Pair(const T& first, const D& second) : first(first), second(second) +{} + +template +const T& Pair::getFirst() const +{ + return first; +} +template +const D& Pair::getSecond() const +{ + return second; +} + +template +void Pair::setFirst(const T& newValue) +{ + first = newValue; +} + +template +void Pair::setSecond(const D& newValue) +{ + second = newValue; +} \ No newline at end of file diff --git a/Sem. 10/Examples/Pair/Source2.cpp b/Sem. 10/Examples/Pair/Source2.cpp new file mode 100644 index 0000000..39229da --- /dev/null +++ b/Sem. 10/Examples/Pair/Source2.cpp @@ -0,0 +1,14 @@ +#include +#include "Pair.hpp" + + + +int main() +{ + Pair p(3, 'd'); + + std::cout << p.getSecond(); + + p.setSecond('a'); + +} -- cgit v1.3.1-23-gd82d