Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 10 / Examples / Pair
diff options
context:
space:
mode:
2 files changed, 57 insertions, 0 deletions
-rw-r--r--Sem. 10/Examples/Pair/Pair.hpp43
-rw-r--r--Sem. 10/Examples/Pair/Source2.cpp14
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<typename T, typename D>
+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<typename T, typename D>
+Pair<T,D>::Pair(const T& first, const D& second) : first(first), second(second)
+{}
+
+template<typename T, typename D>
+const T& Pair<T, D>::getFirst() const
+{
+ return first;
+}
+template<typename T, typename D>
+const D& Pair<T, D>::getSecond() const
+{
+ return second;
+}
+
+template<typename T, typename D>
+void Pair<T, D>::setFirst(const T& newValue)
+{
+ first = newValue;
+}
+
+template<typename T, typename D>
+void Pair<T, D>::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 <iostream>
+#include "Pair.hpp"
+
+
+
+int main()
+{
+ Pair<int, char> p(3, 'd');
+
+ std::cout << p.getSecond();
+
+ p.setSecond('a');
+
+}