I'm trying to achieve a thing. My requirements are C++03 and no external libraries.
I have objects of two different classes, and I'd like them to be able to communicate. My first attempt had each class hold a pointer to the other, and use the pointer to call a member function when some condition is met
class A;
class B;
class A
{
public:
void foo();
void notify();
B* partner;
};
class B
{
public:
void bar();
void notify();
A* partner;
}
void A::foo()
{
partner->notify();
}
void B::bar()
{
partner->notify();
}
The problem for me was in my actual example, A and B were in different source files, and the now A.h includes B.h and vise versa. My thought is I can't just omit the includes and do a forward declare of the class because A needs not only to know about B, but about B's member function as well.
What's a clean and simple way to do this?
edit: In the question linked, the two classes were not calling each other's member functions, so a forward declare of the classes were sufficient. I'd like to be able to call each other's member functions (or have someone suggest a different way of passing information between the two objects)