www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to specify which parameters a function that is received as an

reply Marcone <marcone email.com> writes:
How to specify which parameters a function that is received as an 
argument should receive?

Example:

import std;

void myfun(int n){
     writeln(n);
}


void test(lazy void delegate() fun) // how specify that "fun" may 
receive int ?
{
     fun(int);
}

test({myfun;});
Oct 13 2020
parent Mitacha <mateusz.mitaszka gmail.com> writes:
On Tuesday, 13 October 2020 at 09:02:04 UTC, Marcone wrote:
 How to specify which parameters a function that is received as 
 an argument should receive?

 Example:

 import std;

 void myfun(int n){
     writeln(n);
 }


 void test(lazy void delegate() fun) // how specify that "fun" 
 may receive int ?
 {
     fun(int);
 }

 test({myfun;});
You need to change signature of your function to: ``` void test(lazy void delegate(int) fun) /// ^ this is all you need :D ``` And then pass some value to `fun` Working example: https://run.dlang.io/is/B9bbVl
Oct 13 2020