title: Forward declaration and circular dependencies in C++
body: <p>I am trying to implement a simple relationship in C++. It goes like this:</p>
  <ul>
  <li>teleport changes objects location from one lane to another</li>
  <li>lane holds some other objects as well as multiple teleports.
  This presents a circular dependencies problem, that I can't solve.
  I am already using forward declarations and I have no idea what to do next.</li>
  </ul>
  <p>Lane.h</p>
  <pre><code>#include &quot;Teleport.h&quot;
      class Lane
      {
      public:
          std::map&lt;long long, object&gt; object_container;
          std::map&lt;long long, Teleport&gt; teleports_container;
  
          void add_Object(///) { object_container.emplace(//object//); }
          void add_Teleport(const Teleport &amp;t) { teleport_container.emplace(t._uid, t); }
  
          Object &amp;get_Object(long long uid) { return object_container.at(uid); }
          Teleport &amp;get_Teleport(long long uid) { return teleports_container.at(uid); }
      }
  </code></pre>
  <p>Teleport.cpp</p>
  <pre><code>#include &quot;Lane.h&quot;
  #include &quot;Teleport.h&quot;
  
      void Teleport::teleport_Object(long long tp_uid)
      {
          _destination.add_Object(_origin.get_Object(tp_uid));
      }
  }
  </code></pre>
  <p>Teleport.h</p>
  <pre><code>  class Lane;
  
    class  Teleport
     {
      public:
          const Lane &amp;_origin;
          const Lane &amp;_destination;
  
          Teleport(const Lane &amp;origin, const Lane &amp;destination)
              : _origin{origin}, _destination{destination}{}
  
          void teleport_Object(long long tp_uid);
      };
  
  </code></pre>
  <p>Compile error for Teleport.cpp &quot; error: invalid use of incomplete type ‘const class Lane’&quot;
  Would appreciate any help.</p>