summaryrefslogtreecommitdiffstats
path: root/inheritance.hpp
blob: 6fbc48ee91d02a2dbeaa140c0bbbc2f1fd8db816 (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
#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;
};