883d502ea117c11975554cb29e39a903692a9228
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();
187 int A::f() {return 1;}
188 int B::f() {return 2;}
190 int E::f() {return 20;}
191 int D::vg() {return 100+d
;}
192 int E::vg() {return 200+d
;}
193 int V::f() {return 600+w
;}
194 int V::vv() {return 400+w
;}
195 int E::vv() {return 450+w
;}
196 int D::fd() {return 250+d
;}
197 int D::vd() {return 280+d
;}
198 int VB::fvb() {return 300+vb
;}
199 int VB::vvb() {return 400+vb
;}
This page took 0.037017 seconds and 3 git commands to generate.