blob: 85347694a130d9d10cf7957754db5fbd82a11711 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}
|