delegate reference
Saaa
empty at needmail.com
Wed Sep 9 09:55:57 PDT 2009
>
> 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.
Thanks!
More information about the Digitalmars-d-learn
mailing list