I am trying to use function pointers in program with two classes.
Here's my setup:
In Class A I have a public method defined as [int doSomthing(int a) ].
In Class B I need a method to set a callback for a method [ int callback(int)]
This all works well if the callback function i give is not a member of class A or any other class.
A.cpp:187: error: no matching function for call to ‘B::setTrigger(int (A::*)(int))’
B.h:81: note: candidates are: void B::setTrigger(int (*)(int))
Do I need to specify in class B that the call back needs to be from class A or is there a way to make it more dynamic so when I want class C to set the callback it doesn't break.
Here is an overview of the code
Expand|Select|Wrap|Line Numbers
- class A {
- public:
- int doSomthing(int i);
- }
- class B {
- public:
- typedef int (*Trigger)(int level);
- Trigger TriggerCallback; // This is what I set with setTrigger
- void setTrigger(int (*callback)(int responce));
- }