Pages: [1]   Go Down
Author Topic: Can someone help?! static member function pointer  (Read 1575 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is what I have:

I have a few static member functions that belong to phi_menu class. I want them static just because they can be used on things other than menus (phi_menu instances).

static phi_menu::render_big_number(int number);// Renders big fonts on 16X2 LCD
static phi_menu::render_regular_number(int number);// Renders regular size font on 16X2 LCD
...

Here is what I want to do:
I want to use a pointer to call them:

phi_menu::get_user_input(current, min, max, step, (phi_menu::*update function));

Where the update function can be one of the above static member functions. So if I want to render large numbers I can pass pointer to render_big_number, or if I want regular number, I can pass pointer to the other function.

I tried many things, I admit I don't know much about member function pointers, I couldn't invoke the function.

Here is what I tried to invoke the member function with pointer:
First I pass an address:

phi_menu::get_user_input(current, min, max, step, (&phi_menu::*render_big_number));

This line passed compiler (I think).

Next inside get_user_input I tried to invoke the member function:

 (->*update_function)(number);
Error:expected primary-expression before '->*' token. OK I don't have an instance but do I really need an instance for static member functions?

 (fake->*update_function)(number);
Same error. This time I thought I instantiated a "fake" in .h file.

Then I read up on "static member pointer being the same as regular function pointer" stuff. What does it mean? I used regular stuff before and it didn't work?!

C++ gurus please help! I was gonna release my phi_menu tonight but I couldn't. I really want a class wrapper around everything!

Thanks you!
 smiley-cry smiley-cry smiley-cry

Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I want to use a pointer to call them

Why?  Do you expect the user to provide their own render function?
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 211
Posts: 13471
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have a few static member functions that belong to phi_menu class. I want them static just because they can be used on things other than menus (phi_menu instances).
Think it should be the other way around. You must define some static functions that your menu can call.  The semnatics make more sense that way.

NB it makes no sense to call a menu function to render something, I want to call a render class function. If the menu needs to render something it can also call the render class function (or it may inherit it like the print() functions) .  Think OO
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I posted it here. It's not really 100% programming questions but 50% programming 50% developing a library for arduino. I'm split in between.

After I posted this I have been thinking how to sort out everything. I don't want users to use static menu renderers, but rather, renderers that can render for menu or general purpose, plus interaction functions that don't necessarily tie to just menu, like soliciting an input from a user can be used without being a menu. Those functions should be just left as functions without a class but they do need access to lcd an all keys, which are stored as static member variables in the menu class. Still trying to figure out the overall plan.

Thank you!
Logged


Pages: [1]   Go Up
Jump to: