title: C++ invalid use of incomplete type
body: <p>I have the following files: main.cpp, class.cpp, class.hpp, student.cpp, student.hpp</p>
  
  <p>Here are the codes:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  #include "class.hpp"
  
  
  using namespace std;
  
  
  int main(){
      vector&lt;Student&gt; students;
      vector&lt;Class&gt; classes;
  
      Class B4( 4, 'B' );
      classes.push_back( B4 );
  
      Student john( "John", "Boss", B4 );
      students.push_back( john );
      Student marc( "Marc", "Solo", B4 );
      students.push_back( marc );
  
      marc.printInfo();
      B4.addStudent( marc );
  
      return 0;
  }
  </code></pre>
  
  <p>class.hpp:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include "student.hpp"
  
  using namespace std;
  
  class Class{
  private:
      int number;
      char letter;
      vector&lt;Student&gt; students;
  
  public:
      Class( int, char );
  
      void addStudent( Student &amp; );
      void printClass();
  };
  </code></pre>
  
  <p>class.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "class.hpp"
  
  
  Class::Class( int number, char letter ){
      this -&gt; number = number;
      this -&gt; letter = letter;
  }
  
  
  void Class::printClass(){
      cout &lt;&lt; this -&gt; number &lt;&lt; "." &lt;&lt; this -&gt; letter &lt;&lt; endl;
  }
  
  
  void Class::addStudent( Student &amp; student ){
      this -&gt; students . push_back( student );
  }
  </code></pre>
  
  <p>student.hpp:</p>
  
  <pre><code>#include &lt;string&gt;
  
  using namespace std;
  
  class Class;
  
  class Student{
  private:    
      string name;
      string surname;
      Class* classStudent;
  
  public:
      Student( string name, string surname, Class &amp; );
  
      void printInfo();
  };
  </code></pre>
  
  <p>student.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "student.hpp"
  
  using namespace std;
  
  Student::Student( string name, string surname, Class &amp; classStudent ){
      this -&gt; name            = name;
      this -&gt; surname         = surname;
      this -&gt; classStudent    = &amp;classStudent;
  }
  
  // printInfo
  void Student::printInfo(){
      cout &lt;&lt; "Name: " &lt;&lt; this -&gt; name &lt;&lt; "\nSurname: " &lt;&lt; this -&gt; surname &lt;&lt;
                      "\nClass:" &lt;&lt; this -&gt; classStudent -&gt; printClass() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>When I compile these files I get the following errors:</p>
  
  <pre><code>student.cpp: In member function ‘void Student::printInfo()’:
  student.cpp:15:41: error: invalid use of incomplete type ‘class Class’
        "\nClass:" &lt;&lt; this -&gt; classStudent -&gt; printClass() &lt;&lt; endl;
                                           ^
  In file included from student.cpp:2:0:
  student.hpp:5:7: error: forward declaration of ‘class Class’
   class Class;
         ^
  </code></pre>
  
  <p>I have never came to the situation like this one: that I need to use first class in the second class and the second class in the first class.</p>