1 #ifdef DO_VIRTUAL_INHERITANCE
2 #define VIRTUAL virtual
12 Base(int val
) : m_base_val (val
) {}
17 int future_val
= m_base_val
+ input
* 1;
18 printf("Forcasting %d\n", future_val
);
25 class DerivedA
: public VIRTUAL Base
28 DerivedA(int val
) : Base(val
*2), m_a_val(val
) {
29 printf("DerivedA::ctor()->\n");
30 printf("m_base_val=%d\n", m_base_val
);
31 printf("m_a_val=%d\n", m_a_val
);
33 virtual ~DerivedA() {}
39 class DerivedB
: public VIRTUAL Base
42 DerivedB(int val
) : Base(val
), m_b_val(val
*3) {
43 printf("DerivedB::ctor()->\n");
44 printf("m_base_val=%d\n", m_base_val
);
45 printf("m_b_val=%d\n", m_b_val
);
47 virtual ~DerivedB() {}
51 int future_val
= m_b_val
+ input
* 2;
52 printf("Forcasting %d\n", future_val
);
60 main(int argc
, char **argv
)
62 DerivedA
* dA
= new DerivedA(10);
63 DerivedB
* dB
= new DerivedB(12);
64 Base
*array
[2] = {dA
, dB
};
66 for (int i
= 0; i
< 2; ++i
) {
68 teller
->forcast(i
); // Set breakpoint here.