Member delegate/fp to another member in same object?

Juanjo Alvarez via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 2 10:22:25 PDT 2017


On Tuesday, 2 May 2017 at 17:08:11 UTC, Juanjo Alvarez wrote:
> Example:
>
> struct S {
>   int someState;
>   void some_foo() { return this. someState;}
>
>   void delegate() foo;
>
>   void enable() {
>     foo = &some_foo;
>   }
> }
>
> unittest {
>   S s;
>   s.someState = 1;
>   enable();
>   s.someState = 2;
>   assert(foo == 2);
>   // fails because the delegate keeps
>   // the state of the object at the
>   // assignment point
> }

Forget it. I just noticed the simplified example that I just 
posted works (once the typo of the return value is corrected) but 
my more complex real code won't, will try to get a simple snippet 
where I can reproduce the problem.


More information about the Digitalmars-d-learn mailing list