Q:

forward class friend declaration

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)

A:

What you're trying to do right now would make your classes infinitely large (as I understand, bar and foo are class member variables, hence this means that B includes A, which includes B, ...).
You could use pointers and store A* foo or B* bar in one of your classes or somehow redesign your application to avoid this circular dependency.

