1 // { dg-do run }
2 extern "C" int printf(const char *, ...);
3
4 class A_table {
5 int c;
6 public:
A_table()7 A_table() { c = 3;}
func2(int & item)8 virtual void func2(int &item) { printf("func2(%d,) c=%d\n",item,c);}
9 };
10
11 class B_table : private A_table {
12 public:
13 typedef void (B_table::* B_ti_fn) (int &item);
B_table()14 B_table() { j = 0x4321;}
15 virtual void call_fn_fn1(int &item, void *pfn1);
func1(int & item)16 void func1(int &item) { printf("func1(%d)\n",item);}
func2(int & item)17 virtual void func2(int &item) { printf("func2(%d) j=%d\n",item,j);}
18 int j;
19 };
20
21 class foo : public A_table {
22 public:
23 int i;
24 virtual ~foo();
func2(int & item)25 virtual void func2(int &item) { printf("func2(%d) i=%d\n",item,i);}
26 };
~foo()27 foo::~foo() { i = 0;}
28
29 class bar :public foo,public B_table {
30 public:
31 int w;
32 virtual ~bar();
func2(int & item)33 virtual void func2(int &item) { printf("func2(%d) w=%d\n",item,w);}
34 };
~bar()35 bar::~bar() { w = 0;}
36
call_fn_fn1(int & item,void * pfn1)37 void B_table::call_fn_fn1(int &item, void *pfn1) {
38 (this->*(*(B_ti_fn*)pfn1))(item);
39 }
40
41 B_table b;
42 bar jar;
43
main()44 int main() {
45 printf("ptr to B_table=%x, ptr to A_table=%x\n",&b,(A_table*)&b);
46 B_table::B_ti_fn z = &B_table::func1;
47 int j = 1;
48 jar.call_fn_fn1(j,(void *)&z);
49 j++;
50 z = &B_table::func2;
51 b.call_fn_fn1(j,(void *)&z);
52 j++;
53 jar.call_fn_fn1(j,(void *)&z);
54 return 0;
55 }
56