I have a problem handling a function pointer.I have made a class Control that has a function pointer as member:
void (*mouseFunction) (Control*, Event*);
The member is protected, and it has setter and getter:
void (*getMouseFunction()) (Control*,Event*)
{
return mouseFunction;
}
void setMouseFunction( void (*mouseFunction) (Control*, Event*) )
{
this->mouseFunction=mouseFunction;
}
The problem is that even after setting the pointer, it’s always NULL.
I have a function declared inside a header file:
void mouseFunction (Control* control, Event* event)
{
std::cout << "Inside Text Field";
}
If I try to assign it:
myControlInstance.setMouseFunction(mouseFunction);
If I use the getter to get the pointer it’s NULL; and if I try to execute the function I get EXC_BAD_ACCESS:
error: address doesn't contain a section that points to a section in a object file
Following cod is working, so be sure that youre method is public to be accessible from other place than object.