If class A contains class B , and class B also contains class A , then no, you cannot do this.
class B; // forward declaration of name only. Compiler does not know how much // space a B needs yet. class A { private: B b;
Even if this works, there will be no way to create an instance.
B b; // allocates space for a B // which needs to allocate space for its A // which needs to allocate space for its B // which needs to allocate space for its A // on and on...
However, they may contain pointers (or links) to each other.
class B;
source share