1 // { dg-do run } 2 struct base 3 { 4 int total; addbase5 virtual void add (int i) { total += i; } subbase6 virtual void sub (int i) { total -= i; } initbase7 virtual void init (void) { total = 73; } 8 }; 9 10 struct derived : public base 11 { 12 int total; addderived13 virtual void add (int i) { total += 10 * i; } subderived14 virtual void sub (int i) { total -= 2 * i; } initderived15 virtual void init (void) { total = 0; } 16 }; 17 18 bool get_cond_value(int x)19get_cond_value (int x) 20 { 21 if ((x % 3) > 0) 22 return true; 23 else 24 return false; 25 26 return false; 27 } 28 29 int main(int argc,char ** argv)30main (int argc, char **argv) 31 { 32 base *a; 33 bool cond_value = get_cond_value (10); 34 int x; 35 36 if (cond_value) 37 a = new base (); 38 else 39 a = new derived (); 40 41 cond_value = get_cond_value (47); 42 x = 0; 43 if (!cond_value) 44 x = 17; 45 46 a->init (); 47 48 for ( ; x < 10; ++x) 49 { 50 a->add(50); 51 a->sub(25); 52 } 53 } 54