Go Down

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

dusti

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:

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

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


I get the following error:
Quote
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,
dusti

PaulS

Code: [Select]
MenuItem::MenuItem(void (*cbFunction(MenuItem *)))
Some of the parens are in the wrong places. Should be:
MenuItem::MenuItem(void (*cbFunction)(MenuItem *))

dusti

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.

PaulS

With just code snippets, that's all the help I can provide. Post all of your code, and I can try it myself.

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!

Arduino
via Egeo 16
Torino, 10131
Italy