Function as parameter of a function with parameters

M

marc

Hello,

I can do :

void DoFunct(void (*funcp)());

void MyFunct()
{
//...
}

DoFunct(MyFunct);

but is it possible to pass to DoFunct() a function MyFunct with
parameters ?

Thanks in advance.
 
J

James Kuyper

marc said:
Hello,

I can do :

void DoFunct(void (*funcp)());

void MyFunct()
{
//...
}

DoFunct(MyFunct);

but is it possible to pass to DoFunct() a function MyFunct with
parameters ?

Thanks in advance.

void DoFunct(void(*funcp)(int));

void MyFunct(int i)
{
// ...
}

int main(void)
{
DoFunct(MyFunct);
// ...
}
 
M

marc

int main(void)
{
        DoFunct(MyFunct);

Thanks for your answer, but my problem is how can I pass and read the
parameters of MyFunct ?

DoFunct(MyFunct(1)); => doesn't compile.

And inside DoFunct, I'm not able to read the parameters :
This doesn't compile=>

void DoFunct(void(*funcp)(int i))
{
(*funcp)(i);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top