summaryrefslogtreecommitdiffstats
path: root/inheritance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'inheritance.cpp')
-rw-r--r--inheritance.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/inheritance.cpp b/inheritance.cpp
new file mode 100644
index 0000000..8534769
--- /dev/null
+++ b/inheritance.cpp
@@ -0,0 +1,57 @@
+#include "inheritance.hpp"
+
+container::container(std::size_t max_size_) : max_size(max_size_) {
+ // intialize storage
+ m_storage = new int[max_size];
+}
+
+container::~container() {
+ if (m_storage != nullptr)
+ delete m_storage;
+}
+
+void lifo::add(int v) {
+ push(v);
+}
+
+int lifo::get() {
+ return pop();
+}
+
+void lifo::push(int v) {
+ if (m_top >= max_size)
+ return;
+
+ m_storage[m_top++] = v;
+}
+
+int lifo::pop() {
+ if (m_top <= 0)
+ return 0;
+
+ return m_storage[--m_top];
+}
+
+
+void fifo::add(int v) {
+
+}
+
+int fifo::get() {
+ return 0;
+}
+
+
+int main(int argc, char *argv[]) {
+
+ container *c = new lifo(2);
+
+ c->add(1);
+ c->add(2);
+
+ lifo *b = static_cast<lifo *> (c);
+
+ b->push(2);
+
+ delete c;
+}