Re: delegate reference

2009-09-09 Thread Saaa
>> Or does the compiler handle them like any >> other >> function and just thinks of a name itself ? > > Exactly. If you compile with DMD and the -v flag you can see what names it > gives them. :) nice Thanks!

Re: delegate reference

2009-09-09 Thread BCS
Hello Saaa, Hello Saaa, How should I do this then? C c; C2 c2 = new C2; C3 c3 = new C3; c=c2; auto dg = { return c.method(); }; c=c3; I actually did it like this before :) Thanks But like this I need to do the "c is null" checking within the function literal. I'm not sure how these functi

Re: delegate reference

2009-09-09 Thread Saaa
> Hello Saaa, > >> How should I do this then? > > C c; > C2 c2 = new C2; > C3 c3 = new C3; > c=c2; > > auto dg = { return c.method(); }; > > c=c3; I actually did it like this before :) Thanks But like this I need to do the "c is null" checking within the function literal. I'm not sure how these

Re: delegate reference

2009-09-09 Thread BCS
Hello Saaa, How should I do this then? C c; C2 c2 = new C2; C3 c3 = new C3; c=c2; auto dg = { return c.method(); }; c=c3;

Re: delegate reference

2009-09-09 Thread BCS
Hello Saaa, "Daniel Keep" wrote in message news:h88i4n$235...@digitalmars.com... Saaa wrote: "Daniel Keep" wrote in message news:h88cck$1or...@digitalmars.com... Saaa wrote: abstract class C { int method(); } class C2:C { int method() return 2; } class C3:C { int method() return 3; } i

Re: delegate reference

2009-09-09 Thread Saaa
> > class Foo > { > C* c; > > this(ref C c) > { >this.c = &c; > } > > int invoke() > { >return (*c).method(); > } > } > > void main() > { > // ... > deleg = &(new Foo(c)).invoke; > } > > Or something similar. > > This is dangerous. Do not allow either the Foo instance or the deleg

Re: delegate reference

2009-09-09 Thread Daniel Keep
Saaa wrote: > Ok, disregard my last comment :D > How should I do this then? class Foo { C* c; this(ref C c) { this.c = &c; } int invoke() { return (*c).method(); } } void main() { // ... deleg = &(new Foo(c)).invoke; } Or something similar. This is dangerous. Do n

Re: delegate reference

2009-09-09 Thread Saaa
"Daniel Keep" wrote in message news:h88i4n$235...@digitalmars.com... > > > Saaa wrote: >> "Daniel Keep" wrote in message >> news:h88cck$1or...@digitalmars.com... >>> >>> Saaa wrote: abstract class C { int method(); } class C2:C { int method() return 2;

Re: delegate reference

2009-09-09 Thread Saaa
"Ary Borenszweig" wrote in message news:h88i6o$23h...@digitalmars.com... > Saaa wrote: >> "Daniel Keep" wrote in message >> news:h88cck$1or...@digitalmars.com... >>> >>> Saaa wrote: abstract class C { int method(); } class C2:C { int method() return 2;

Re: delegate reference

2009-09-09 Thread Ary Borenszweig
Saaa wrote: "Daniel Keep" wrote in message news:h88cck$1or...@digitalmars.com... 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; c

Re: delegate reference

2009-09-09 Thread Daniel Keep
Saaa wrote: > "Daniel Keep" wrote in message > news:h88cck$1or...@digitalmars.com... >> >> Saaa wrote: >>> abstract class C >>> { >>> int method(); >>> } >>> class C2:C >>> { >>> int method() return 2; >>> } >>> class C3:C >>> { >>> int method() return 3; >>> } >>> int delegate() deleg; >>>

Re: delegate reference

2009-09-09 Thread Saaa
"Daniel Keep" wrote in message news:h88cck$1or...@digitalmars.com... > > > 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; >> C

Re: delegate reference

2009-09-09 Thread Daniel Keep
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 >

delegate reference

2009-09-09 Thread Saaa
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 wr