Say I have a class foo with an object of class bar as a member
class foo
{
bar m_bar;
};
Now suppose bar needs to keep track of the foo
In your example, foo depends on bar (because it contains an actual bar object), but bar does not depend on foo (since it only contains a foo *). Now bar does depend on on foo being a type name, so bar.h needs a forward declaration of the name: class foo;. foo depends on bar, so foo.h should contain #include "bar.h"
You can't have classes that directly depend on each other in C++; it simply doesn't work. You need to decouple the classes such that one only depends on the other existing, like in your example. The only things that create a direct dependence are using a class as a base class or as a field; any other use just creates an indirect dependence, which is generally not a problem.