You can't. If one of the headers only have pointers or references to the other class and never actually access the object it's enough to add a forward declaration.
Hi! Thanks for the reply! I'm just beginning with C++ so could you explain a bit more? I'm sorry if this is to much to ask, but I am really eager to learn how to do what you just did!
@Peter87
#include "B.h"
class A
{
public:
void foo();
private:
B a;
};
B.h
1 2 3 4 5 6 7
class A;
class B
{
public:
void bar(A& a);
};
In the above example A has a data member of type B so it necessary to include B.h. The only use of A in B is a reference so we don't have to include A.h. Including A.h from B.h wouldn't even work because they include each other. We still need to tell the compiler that A is a class so for that reason we put a forward declaration of A (line 1) in B.h. In B.cpp you will probably have to include A.h, otherwise you will not be able to access the A object (call member functions, etc.) from the A reference.