1#ifdef DO_VIRTUAL_INHERITANCE
2#define VIRTUAL virtual
3#else
4#define VIRTUAL
5#endif
6
7#include <stdio.h>
8
9class Base
10{
11public:
12 Base(int val) : m_base_val (val) {}
13 virtual ~Base() {}
14
15 virtual void
16 forcast(int input) {
17 int future_val = m_base_val + input * 1;
18 printf(format: "Forcasting %d\n", future_val);
19 }
20
21protected:
22 int m_base_val;
23};
24
25class DerivedA : public VIRTUAL Base
26{
27public:
28 DerivedA(int val) : Base(val*2), m_a_val(val) {
29 printf(format: "DerivedA::ctor()->\n");
30 printf(format: "m_base_val=%d\n", m_base_val);
31 printf(format: "m_a_val=%d\n", m_a_val);
32 }
33 virtual ~DerivedA() {}
34
35private:
36 int m_a_val;
37};
38
39class DerivedB : public VIRTUAL Base
40{
41public:
42 DerivedB(int val) : Base(val), m_b_val(val*3) {
43 printf(format: "DerivedB::ctor()->\n");
44 printf(format: "m_base_val=%d\n", m_base_val);
45 printf(format: "m_b_val=%d\n", m_b_val);
46 }
47 virtual ~DerivedB() {}
48
49 virtual void
50 forcast(int input) {
51 int future_val = m_b_val + input * 2;
52 printf(format: "Forcasting %d\n", future_val);
53 }
54
55private:
56 int m_b_val;
57};
58
59int
60main(int argc, char **argv)
61{
62 DerivedA* dA = new DerivedA(10);
63 DerivedB* dB = new DerivedB(12);
64 Base *array[2] = {dA, dB};
65 Base *teller = NULL;
66 for (int i = 0; i < 2; ++i) {
67 teller = array[i];
68 teller->forcast(input: i); // Set breakpoint here.
69 }
70
71 return 0;
72}
73

source code of lldb/test/API/lang/cpp/dynamic-value/sbvalue-cast.cpp