title: Circular Dependencies / Incomplete Types
body: <p>In C++, I have a problem with circular dependencies / incomplete types. The situation is as follows:</p>
  
  <p>Stuffcollection.h</p>
  
  <pre><code>#include "Spritesheet.h";
  class Stuffcollection {
      public:
      void myfunc (Spritesheet *spritesheet);
      void myfuncTwo ();
  };
  </code></pre>
  
  <p>Stuffcollection.cpp</p>
  
  <pre><code>void Stuffcollection::myfunc(Spritesheet *spritesheet) {
      unsigned int myvar = 5 * spritesheet-&gt;spritevar;
  }
  void myfunc2() {
      //
  }
  </code></pre>
  
  <p>Spritesheet.h</p>
  
  <pre><code>#include "Stuffcollection.h"
  class Spritesheet {
      public:
      void init();
  };
  </code></pre>
  
  <p>Spritesheet.cpp</p>
  
  <pre><code>void Spritesheet::init() {
      Stuffcollection stuffme;
      myvar = stuffme.myfuncTwo();
  }
  </code></pre>
  
  <ul>
  <li>If I keep the includes as shown above, I get the compiler error
  <code>spritesheet has not  been declared</code> in Stuffcollection.h (line 4 in
  the above). I understand this to be due to a circular dependency. </li>
  <li>Now if I change <code>#include "Spritesheet.h"</code> to the Forward
  Declaration <code>class Spritesheet;</code> in Stuffcollection.h,  I get  the
  compiler error <code>invalid use of incomplete type 'struct Spritesheet'</code>
  in Stuffcollection.cpp (line 2 in the above).</li>
  <li>Similarly, if I change <code>#include "Stuffcollection.h"</code> to <code>class
  Stuffcollection;</code> in Spritesheet.h, I get the compiler error <code>aggregate
  'Stuffcollection stuffme' has incomplete type and cannot be defined</code>
  in Spritesheet.cpp (line 2 in the above).</li>
  </ul>
  
  <p>What can I do to solve this problem?</p>