Go Down

Topic: Callback function not compiling (Read 668 times) previous topic - next topic


I want to write a menu library for TFT touch screens. I need to have callback functions for when a MenuItem is selected. I wrote the following constructor:

Code: [Select]
MenuItem(void (*cbFunction)(MenuItem *));

Code: [Select]
MenuItem::MenuItem(void (*cbFunction(MenuItem *)))
    // Code...

I get the following error:
MenuItem.cpp:13: error: prototype for 'MenuItem::MenuItem(void* (*)(MenuItem*))' does not match any in class 'MenuItem'
MenuItem.h:7: error: candidates are: MenuItem::MenuItem(const MenuItem&)
MenuItem.h:13: error:                 MenuItem::MenuItem(String, void (*)(MenuItem*), MenuItem::inputMode)
MenuItem.h:12: error:                 MenuItem::MenuItem(void (*)(MenuItem*))
MenuItem.cpp:8: error:                 MenuItem::MenuItem(String)
MenuItem.cpp:3: error:                 MenuItem::MenuItem()

Why is there a * after the void (return type of the callback function) in the first line of the error message? Can someone help me and explain why this isn't working and how i could correct it?

Thanks in advance,


Code: [Select]
MenuItem::MenuItem(void (*cbFunction(MenuItem *)))
Some of the parens are in the wrong places. Should be:
MenuItem::MenuItem(void (*cbFunction)(MenuItem *))
The art of getting good answers lies in asking good questions.


Thank you, you are right. But i still get the same error: The only difference between my implementation and the candidate is, that the candidate has a * behind the void and i don't know from where this asterisk comes from.


With just code snippets, that's all the help I can provide. Post all of your code, and I can try it myself.
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131