title: C++ declaring multiple classes in one header
body: <p>I got an assignment where I am supposed to create a Linked list by using CRTP. I got some starting code/suggestion on how to define the classes in their respective header files. I have omitted some code below:</p>
  
  <p><em>Link.h</em></p>
  
  <pre><code>#include &lt;iosfwd&gt;
  
  template&lt;class T&gt;
  class List;
  
  template&lt;class T&gt;
  class Link {
      Link* next;
  
      friend class List&lt;T&gt;;
  
  public:
      Link();
  
      virtual ~Link() = default;
    //etc...
  </code></pre>
  
  <p><em>List.h</em></p>
  
  <pre><code>#include "Link.h"
  
  
  template&lt;class T&gt;
  class List : public Link&lt;T&gt; {
  public:
      List();
  
      T* First();
  
      T* Last();
      //Etc...
  </code></pre>
  
  <p>This code compiles without any errors. Now my question is about the two first lines in Link.h, <code>template&lt;class T&gt; class List;</code>. I experimented a little bit and realized that Link.h won't compile without that class definition beacuse of the <code>friend class List&lt;T&gt;</code>  statement. But why can't I just write <code>#include "List.h"</code> and remove the inheritance inside List.h and just use that definition from the start? I have tried this of course and get the error </p>
  
  <pre><code>"error: 'List' is not a class template
       friend class List&lt;T&gt;;"
  </code></pre>
  
  <p>it would look like this:</p>
  
  <p><em>Link.h</em></p>
  
  <pre><code>#include &lt;iosfwd&gt;
  #include "List.h"
  
  
  template&lt;class T&gt;
  class Link {
      Link* next;
  
      friend class List&lt;T&gt;;
  
  public:
      Link();
  
      virtual ~Link() = default;
  </code></pre>
  
  <p><em>List.h</em></p>
  
  <pre><code>#include "Link.h"
  
  
  template&lt;class T&gt;
  class List {
  public:
      List();
  
      T* First();
  </code></pre>