toDelegate() for D1

%u e at ee.com
Thu Jan 13 09:14:13 PST 2011


== Quote from Simen kjaeraas (simen.kjaras at gmail.com)'s article
> %u <e at ee.com> wrote:
> > I only need something to make a void deleg() from a void func().
> This works for me:
> ReturnType!( F ) delegate( ParameterTypeTuple!( F ) ) toDelegate( F )( F
> fn ) {
>      return ( ParameterTypeTuple!( F ) args ){ return fn( args ); };
> }

What am I doing wrong. I can't call the delegate twice with anything in between.

----
void func(){ writefln("func"); }

void main(){
  void delegate() dg;
  dg = toDelegate(&func);
  dg(); // np
  //writefln(dg.ptr," ", dg.funcptr,"."); // Error: Stack Overflow @ second dg call
  //writefln(); // Error: Access Violation @ second dg call
  dg();
}
----


More information about the Digitalmars-d-learn mailing list