G
ghulands
I am having trouble implementing some function pointer stuff in c++
An object can register itself for many events
void addEventListener(CFObject *target, CFEventHandler callback,
uint8_t event);
so I declared a function pointer like
typedef void (CFObject::*CFEventHandler)(CFEvent *theEvent);
So when I register a handler
plane->addEventListener((CFObject *)gun, &MachineGun::handleEvent, 0);
MachineGun's class contains
void handleEvent(CFEvent *theEvent);
I am getting the following error:
error: no matching function for call to
'Airplane::addEventListener(CFObject*, void (MachineGun::*)(CFEvent*),
uint8_t&)'/Users/ghulands/Desktop/arduino-0012/hardware/libraries/
CoreFoundation/CFApplication.h:42: note: candidates are: void
CFApplication::addEventListener(CFObject*, void (CFObject::*)
(CFEvent*), uint8_t)
MachineGun is a subclass (not a direct one) of CFObject.
If I put an event handler on CFObject it compiles fine. I don't want
to have to put it in there as a virtual method as it will break the
design.
Is there a way for the function pointer definition to be defined in
that it can also accept subclasses of the type?
Any help is greatly appreciated.
Thanks,
Greg
An object can register itself for many events
void addEventListener(CFObject *target, CFEventHandler callback,
uint8_t event);
so I declared a function pointer like
typedef void (CFObject::*CFEventHandler)(CFEvent *theEvent);
So when I register a handler
plane->addEventListener((CFObject *)gun, &MachineGun::handleEvent, 0);
MachineGun's class contains
void handleEvent(CFEvent *theEvent);
I am getting the following error:
error: no matching function for call to
'Airplane::addEventListener(CFObject*, void (MachineGun::*)(CFEvent*),
uint8_t&)'/Users/ghulands/Desktop/arduino-0012/hardware/libraries/
CoreFoundation/CFApplication.h:42: note: candidates are: void
CFApplication::addEventListener(CFObject*, void (CFObject::*)
(CFEvent*), uint8_t)
MachineGun is a subclass (not a direct one) of CFObject.
If I put an event handler on CFObject it compiles fine. I don't want
to have to put it in there as a virtual method as it will break the
design.
Is there a way for the function pointer definition to be defined in
that it can also accept subclasses of the type?
Any help is greatly appreciated.
Thanks,
Greg