class A;
class B
{
public:
A *a;
void Init(A *param);
void Ok();
};
class A
{
public:
B b;
void Init();
void Ok();
};
void B::Init(A *param)
{
printf("Init B\n");
a = param;
a->Ok();
}
void B::Ok()
{
printf("OK B!\n");
}
void A::Init()
{
printf("Init A\n");
b.Init(this);
}
void A::Ok()
{
printf("OK A!\n");
b.Ok();
}
The forward declaration of A is necessary to define the pointer member and parameter in B. The full definition of B is then necessary so that it can be a member of A. Finally, the member functions are defined once all classes are fully defined.