Two functions with different args. Taking address of the one

Paul Backus snarwin at gmail.com
Thu Mar 11 12:48:13 UTC 2021


On Thursday, 11 March 2021 at 12:26:07 UTC, Виталий Фадеев wrote:
> Have:
>     void process( ref MouseKeyEvent event )
>     {
>        ...
>     }
>
>     void process( ref MouseMoveEvent event )
>     {
>        ...
>     }
>
> Want:
>     _processMouseKey  = &process; // <-- not works
>     _processMouseMove = &process; // <-- not works
>
> What is correct way to get address of function with specific 
> argument ?

You can use __traits(getOverloads, process) plus some 
metaprogramming to get the address of a specific overload. But 
IMO the easiest way is to use lambdas:

     __processMouseKey = (ref MouseKeyEvent event) { 
process(event); };
     __processMouseMove = (ref MouseMoveEvent event) { 
process(event); };


More information about the Digitalmars-d-learn mailing list