delegate reference

Daniel Keep daniel.keep.lists at gmail.com
Wed Sep 9 09:04:46 PDT 2009


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 not allow either the Foo instance or the delegate
to survive past the end of c's scope.

It is simpler and safer to just update the delegate.


More information about the Digitalmars-d-learn mailing list