1 // Pls try the following program on virtual functions and try to do print on
2 // most of the code in main(). Almost none of them works !
5 // The inheritance structure is:
29 class V
: public VA
, public VB
37 class A
: virtual public V
53 class C
: public virtual V
65 class D
: public AD
, virtual public V
75 class E
: public B
, virtual public V
, public D
, public C
130 extern "C" int printf(const char *, ...);
133 int failed_count
= 0;
135 #define TEST(EXPR, EXPECTED) \
137 if (ret != EXPECTED) {\
138 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
149 TEST(pDe
->vg(), 202);
150 TEST(pADe
->vg(), 202);
151 TEST(pDd
->vg(), 101);
153 TEST(pEe
->vvb(), 411);
155 TEST(pVB
->vvb(), 407);
157 TEST(pBe
->vvb(), 411);
158 TEST(pDe
->vvb(), 411);
160 TEST(pEe
->vd(), 282);
161 TEST(pEe
->fvb(), 311);
163 TEST(pEe
->D::vg(), 102);
164 printf("Did %d tests, of which %d failed.\n", all_count
, failed_count
);
168 void set_debug_traps();
189 int A::f() {return 1;}
190 int B::f() {return 2;}
192 int E::f() {return 20;}
193 int D::vg() {return 100+d
;}
194 int E::vg() {return 200+d
;}
195 int V::f() {return 600+w
;}
196 int V::vv() {return 400+w
;}
197 int E::vv() {return 450+w
;}
198 int D::fd() {return 250+d
;}
199 int D::vd() {return 280+d
;}
200 int VB::fvb() {return 300+vb
;}
201 int VB::vvb() {return 400+vb
;}