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 that owns it

class bar
{
    foo * m_pfoo;
}

The two classes reference each other and without a forward declaration, will not compile. So adding this line before foo's declaration solves that problem

class bar;

Now, here is the problem - when writing the header files, each header depends on the other: foo.h needs the definitions in bar.h and vice-versa. What is the proper way of dealing with this?

Edit
Report