Why function does not work with delegate
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed May 22 22:45:58 UTC 2019
On Wed, May 22, 2019 at 10:33:52PM +0000, Alex via Digitalmars-d-learn wrote:
> In gtkD one can use a lambda directly:
>
> X.addOnButtonPress((GdkEventButton* e, Widget w) ...
>
> but if I try move the lambda in to a variable so I can use it with
> multiple handlers, I get an error:
>
> // x is a function and does not work
> auto x = (GdkEventButton* e, Widget w) ...
> X.addOnButtonPress(x);
>
> etc...
>
> It's because the second case treats x as a function while the first it
> is a delegate and addOnButtonPress requires a delegate...
[...]
You could try explicitly declaring it as a delegate:
void delegate(GdkEventButton*, Widget) x = (e, w) { ... };
X.addOnButtonPress(x);
T
--
I am Ohm of Borg. Resistance is voltage over current.
More information about the Digitalmars-d-learn
mailing list