I have two classes A and B, where I would like to access the private members of B from A.
class A; // Forward declaration
class B {
friend class A; // A is a friend of B
A a; // error: 'B::a' uses undefined class 'A'
private:
int i;
};
class A {
public:
B *m_b;
A(B *i_b) : m_b(i_b) {}; // legal access due to friendship
};
However, I do not understand why I get the following error: 'B::a' uses undefined class 'A'