1 interface I 2 { 3 int foo(); 4 } 5 6 class IA : I 7 { foo()8 int foo() { return 1; } 9 } 10 11 class A 12 { 13 I i; 14 clone()15 I clone() { return i; } 16 } 17 18 class B : A 19 { 20 IA ia; 21 clone()22 IA clone() 23 out (result) 24 { 25 printf("B.clone()\n"); 26 } 27 body { return ia; } 28 } 29 main()30void main() 31 { 32 IA ia = new IA; 33 assert(ia.foo() == 1); 34 35 I i = ia; 36 assert(i.foo() == 1); 37 38 A a = new A; 39 a.i = i; 40 assert(a.clone().foo() == 1); 41 42 B b = new B; 43 b.ia = ia; 44 assert(b.clone().foo() == 1); 45 46 a = b; 47 assert(a.clone().foo() == 1); 48 49 bar(&b.clone); 50 } 51 52 bar(IA delegate ()dg)53void bar(IA delegate() dg) 54 { 55 } 56 57