static / non-static members
I have a static member function that looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void whackamole_window::timer(void*){
if (ttime == 0) {
Fl::remove_timeout(whackamole_window::timer);
}
else {
cout <<ttime <<"\n";
whackamole_window::timebox.put(ttime);
ttime -= 1;
Fl::repeat_timeout(1, whackamole_window::timer);
return;
}
}
|
timebox is a nonstatic member of whackamole
When I run this code I get the following error:
mole111j.cpp:115: member `whackamole_window::timebox' is non-static but
referenced as a static member
|
The code won't work if I make timebox static. How can I work around this?
I've been told that I could use a pointer but I have no clue how to do that.
Why is the method static in the first place? (your method work with the state of the object)
It had to be static because I could only get the timer to work if the callback in add_timeout was static.
I managed to solve my problem by using pointers and creating a corresponding non-static member. Thank you for your concern, though.
Topic archived. No new replies allowed.