FuncPointer doesn't work
Hi everybody,
I am in first year at uni and need to do a little c++ app...
The problem is I have a Event Class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
typedef void (*FuncDownPtr)(void);
typedef void (*FuncOverPtr)(int,int);
class Event {
private:
FuncDownPtr DownFunc;
FuncOverPtr OverFunc;
public:
int type;
int state;
Event();
void RegisterDownFunc(FuncDownPtr Func);
void RegisterOverFunc(FuncOverPtr Func);
void CallDownFunc(void);
void CallOverFunc(int x, int y);
};
|
and in the related *.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Event::Event() {
DownFunc = NULL;
OverFunc = NULL;
type=0;
state=0;
}
void Event::RegisterDownFunc(FuncDownPtr Func) {
DownFunc = Func;
}
void Event::RegisterOverFunc(FuncOverPtr Func) {
OverFunc = Func;
}
void Event::CallDownFunc(void) {
if (DownFunc!=NULL)
DownFunc();
}
void Event::CallOverFunc(int x, int y) {
if (OverFunc!=NULL)
OverFunc(x, y);
}
|
So the problem is the RegisterDoneFunc works very well, for example here an instance of the Button Class which is a child of Event-Class:
1 2 3 4 5 6
|
Button *bQuit = new Button(69,22,10,"QUIT");
// set style
bQuit->SetAttributes(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY, BACKGROUND_RED | BACKGROUND_INTENSITY,BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
// init function and register to button
void bQuit_clicked(void);
bQuit->RegisterDownFunc(bQuit_clicked);
|
But in another Class which is a child of Event-Class, I try to call RegisterOverFunc() in the constructor like that:
1 2 3 4
|
RegisterOverFunc(SetFocusCell);
//the SetFocusCell is part of the same class and defined like that:
void SetFocusCell(int x, int y);
|
So the thing is the compiler throws an error for RegisterOverFunc(SetFocusCell); but why?
The error is:
error C3867: 'Sudoku::SetFocusCell': function call missing argument list; use '&Sudoku::SetFocusCell' to create a pointer to member
I hope you can help me,
thanks,
Niklas
P.S: Sorry about the bad english... hope it's readable
Thanks,
helped alot!
It's working now.
Topic archived. No new replies allowed.