Here is my code & requirements:
I have 2 classes A & B, they don't have any inheritance. I used one method of class A to call one method of Class B. Then the class B's method should callback one of the class A's method to execute a callback.
Part of code:
classA.h:
#include "classB.h"
class classA
{
public:
classA();
classB *pClassB;
void callClassB();
void callBack();
};
classA.cpp:
#include "classA.h"
classA::classA()
{
pClassB = new classB();
}
void classA::callBack()
{
return;
}
void classA::callClassB()
{
pClassB->callFunction();
}
classB.h:
class classB
{
public:
classB();
void callFunction();
}
classB.cpp:
#include "classB.h"
classB::classB()
{
}
void classB::callFunction()
{
// I should call classA's callback here!
}
The problem is, I can't include classA.h in classB.h because it will cause some compile issue elsewhere(I can't solve that). I can't make classB as classA's subclass(if I can, I just have to do classA::callBack() instead). So is there a solution to this situation?
UPDATE:that's what I've modified:
class classB
{
public:
classB(classA& pCallBack);
void callFunction();
void (classA::*m_callback)(void);
};
classA::classA()
{
pClassB = new classB(*this);
}
classB::classB(classA& pCallBack)
{
m_callback = pCallBack;
}
I tried to save the pointer, but also failed. It says "assigning from incompatible type"... what's wrong with it??