title: C++ Using Class A as a parameter for member function of Class B with Class B being a member of Class A
body: <p>Basically, I have two classes under two different header files. <code>ToolBar</code> and <code>NewMenu</code> (I will use the actual class names for my better understanding) Both of these classes are under <code>namespace map</code>.  Now I have the class <code>NewMenu</code> declared inside of the class <code>ToolBar</code>.  However, I have a member function in <code>NewMenu</code>, (<code>HandleEvents(..., ToolBar&amp; toolBar)</code>), that handles events, but has the class <code>ToolBar</code> as a parameter in order to pass and edit certain information based on the event that happens.  However, this seems to cause circular-dependency.  </p>
  
  <p>So basically... I started like this...</p>
  
  <pre><code>// ToolBar.h
  #include "NewMenu.h"
  
  namespace map
  {
  class ToolBar
  {
  private:
      NewMenu myNewMenu;
  
  public:
      /* ... */
  }
  } // namespace map
  
  //////////////////////////
  
  // NewMenu.h
  #include "ToolBar.h"
  
  namespace map
  {
  class NewMenu
  {
  private:
      /* ... */
  
  public:
      void HandleEvents(ToolBar&amp; toolBar)
      {
          /* ... */
          //Use ToolBar function
          toolBar.tileMap.Create();
  
          /* ... */
      }
      /* ... */
  }
  } // namespace map
  </code></pre>
  
  <p>However, this causes circular-dependency. So I then did some research trying to solve this and got something like this...</p>
  
  <pre><code>// ToolBar.h
  #include "NewMenu.h"
  
  namespace map
  {
  class ToolBar
  {
  private:
      NewMenu myNewMenu;
  
  public:
      /* ... */
  }
  } // namespace map
  
  //////////////////////////
  
  // NewMenu.h
  //#include "ToolBar.h" 
  
  namespace map
  {
  class ToolBar; //(I presume) to make a temporary reference to class ToolBar.
  class NewMenu
  {
  private:
      /* ... */
  
  public:
      void HandleEvents(ToolBar&amp; toolBar)
      {
          /* ... */
          //Use ToolBar function
          toolBar.tileMap.Create(); //Error: incomplete type is not allowed
  
          /* ... */
      }
      /* ... */
  }
  } // namespace map
  </code></pre>
  
  <p>I'm not 100% sure, but based off of what I gathered, this should basically fix it(?), however, now I get an error in the <code>HandleEvents()</code> function saying "Error: incomplete type is not allowed."  So my question is, what am I getting wrong and how do I fix this circular dependency?</p>
  
  <p>(side note: I got some of my research <a href="https://stackoverflow.com/questions/625799/resolve-circular-dependencies-in-c" title="Resolve circular dependencies in c++">here</a>. Though sometimes I just need things shown a slightly different way to understand)</p>
  
  <p>Thank you for your time and help.</p>