summaryrefslogtreecommitdiffstats
path: root/inheritance.hpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--inheritance.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/inheritance.hpp b/inheritance.hpp
new file mode 100644
index 0000000..6fbc48e
--- /dev/null
+++ b/inheritance.hpp
@@ -0,0 +1,40 @@
+#include <cstddef>
+
+class container {
+public:
+ const std::size_t max_size;
+
+ container() = delete;
+ container(std::size_t max_size);
+ virtual ~container();
+
+ virtual void add(int v) = 0;
+ virtual int get() = 0;
+
+protected:
+ int *m_storage = nullptr;
+};
+
+
+class lifo : public container {
+public:
+ lifo(std::size_t max_size) : container(max_size) {}
+
+ void add(int v) override;
+ int get() override;
+
+ void push(int v);
+ int pop();
+
+private:
+ unsigned m_top = 0;
+};
+
+
+class fifo : public container {
+ fifo(std::size_t max_size) : container(max_size) {}
+
+ void add(int v) override;
+ int get() override;
+};
+