Pages: [1]   Go Down
Author Topic: Callback function not compiling  (Read 375 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
MenuItem(void (*cbFunction)(MenuItem *));

Implementation:
Code:
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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46075
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46075
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: