Hi i have a problem, I try to do the follow, class A depends on class B and vice versa like this
class A;
class B{
A foo;
friend B A::doSomething();
};
class A {
B bar;
B doSomething;
};
The friend declartion does not work because A is an incomplete declartion. Is there any way to avoid this? (Swapp classes declaration order is not a solution I did not want to construct a more complicated example where swapping does not work anymore)
What you’re trying to do right now would make your classes infinitely large (as I understand,
barandfooare class member variables, hence this means thatBincludesA, which includesB, …).You could use pointers and store
A* fooorB* barin one of your classes or somehow redesign your application to avoid this circular dependency.