forward declaration with vector of class type - pointer to incomplete class type not allowed
<p>I have two classes, foo and bar. foo includes bar and contains a std::vector of pointers to bar objects. at some point during runtime, bar has to access this vector of pointers to other bar objects. Therefor, foo contains a method named getBarObjects() that returns the array of pointers.</p>

<p>Therefor, I forward declarate foo in bar. I obvioulsy also have to forward declarate the method I'm using - foo::getBarObjects(). As this returns the array of pointers to bar, I get into a vicious cycle.</p>

<p>I cannot forward include Bar and then simply forward include getBarObjects(), as this results in "incomplete type name is not allowed".</p>

<p>foo.h:</p>

<pre><code>#include "bar.h"
#include &lt;vector&gt;

class foo {
    public:
         foo();
         ~foo();
         std::vector&lt;bar*&gt; getBarObjects();
    private:
         std::vector&lt;bar*&gt; barObjects;
}
</code></pre>

<p>bar.h:</p>

<pre><code>class foo;
std::vector&lt;bar*&gt; foo::getBarObjects();        // error, doesn't know bar at this point

class bar {
    public:
        bar(foo *currentFoo);
        ~bar();
        bool dosth();
    private:
        foo *thisFoo;
}
</code></pre>

<p>bar.cpp:</p>

<pre><code>#include "bar.h"

bool bar(foo *currentFoo) {
    thisFoo = currentFoo;
}

bool bar::dosth() {
    thisFoo-&gt;getBarObjects();        // error, pointer to inomplete class type is not allowed
}
</code></pre>

<p>If I simply include the other way around, I'll have just the same problem in foo lateron. Any suggestions?</p>
