| 1 | #include <stdio.h> |
| 2 | #include <stdint.h> |
| 3 | |
| 4 | class A |
| 5 | { |
| 6 | public: |
| 7 | A(int a) : |
| 8 | m_a(a) |
| 9 | { |
| 10 | } |
| 11 | virtual ~A(){} |
| 12 | virtual int get2() const { return m_a; } |
| 13 | virtual int get() const { return m_a; } |
| 14 | protected: |
| 15 | int m_a; |
| 16 | }; |
| 17 | |
| 18 | class B : public A |
| 19 | { |
| 20 | public: |
| 21 | B(int a, int b) : |
| 22 | A(a), |
| 23 | m_b(b) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | ~B() override |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | int get2() const override |
| 32 | { |
| 33 | return m_b; |
| 34 | } |
| 35 | int get() const override |
| 36 | { |
| 37 | return m_b; |
| 38 | } |
| 39 | |
| 40 | protected: |
| 41 | int m_b; |
| 42 | }; |
| 43 | |
| 44 | struct C |
| 45 | { |
| 46 | C(int c) : m_c(c){} |
| 47 | virtual ~C(){} |
| 48 | int m_c; |
| 49 | }; |
| 50 | |
| 51 | class D : public C, public B |
| 52 | { |
| 53 | public: |
| 54 | D(int a, int b, int c, int d) : |
| 55 | C(c), |
| 56 | B(a, b), |
| 57 | m_d(d) |
| 58 | { |
| 59 | } |
| 60 | protected: |
| 61 | int m_d; |
| 62 | }; |
| 63 | int main (int argc, char const *argv[], char const *envp[]) |
| 64 | { |
| 65 | D *good_d = new D(1, 2, 3, 4); |
| 66 | D *d = nullptr; |
| 67 | return d->get(); |
| 68 | } |
| 69 | |
| 70 | |