How to get the "this" ptr of a lambda inside the lambda?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 18 23:46:44 PDT 2016


On Tuesday, 19 July 2016 at 06:32:32 UTC, Rufus Smith wrote:
> Error: 'this' is only defined in non-static member functions, 
> not __lambda2	
>
> Lambda's are delegates and delegates have a "this" type of 
> pointer. I would like to get at it inside the lambda to check 
> for some things. I'm doing some funky stuff. I'm not concerned 
> about the scope or what this actually pointers to or anything 
> like that, just need it's value for debugging.
>

No, delegates do not have a "this" type of pointer. "this" is an 
implicit function parameter in a class or struct member function. 
Delegates have no such thing. The only generic way I know of to 
get at a delegate's function pointer inside the implementation is 
to explicitly add the pointer type to the parameter list as part 
of the declaration and pass it as an argument when you call the 
delegate.


More information about the Digitalmars-d-learn mailing list