I'm trying to make a simple callback in C++ but I'm having issues doing it as I want to.
Essentially I want something like this:
class A{
void A::AddCallback(void (*callBackFunction)(string)){
/*Code goes here*/
}
}
And class B
#include "A.h"
class B{
B::B(){
A childObject;
childObject(MyCallBackFunction);
}
B::MyCallBackFunction(string arg){
/*Code goes here*/
}
}
I know that usually you would want to define the header of AddCallback
with something like B::callBackFunction
but I do need to import A
in B
so I it would be awkward to have both classes import each other. I know I've seen this before but I cant get the syntax right