delegate reference

Daniel Keep daniel.keep.lists at gmail.com
Wed Sep 9 06:59:55 PDT 2009



Saaa wrote:
> abstract class C
> {
>  int method();
> }
> class C2:C
> {
>  int method() return 2;
> }
> class C3:C
> {
>  int method() return 3;
> }
> int delegate() deleg;
> void main()
> {
>  C c;
>  C2 c2 = new C2;
>  C3 c3 = new C3;
>  c=c2;
>  deleg = &c.method;
>  writefln(deleg()); // 2
>  c=c3;
>  writefln(deleg()); // 2
>  // I expected this to write 3, why is this not so?

Because you didn't reassign deleg.


More information about the Digitalmars-d-learn mailing list