title: C++ Classes dependent on each other causing a cyclic dependency error
body: <p>My searches have lead me to believe that the problem I am experiencing is called cyclic redundancy. I don't understand any of the solutions that are posted. I am (fairly) new to C++, coming from a strong Java background. </p>
  
  <p>Basically there are two classes that depend on each other. Class A contains a vector of class B objects, and class B contains methods that require class A objects as input. </p>
  
  <p>Here's code that reproduces the problem. </p>
  
  <p>According to codelite g++, the error is in school.h and is "person was not declared in this scope". It also says "template argument 1 is invalid" and "template argument number 2 is invalid". Then a couple of others, about non-class type "int" on all the vector functions that get invoked. </p>
  
  <p>main.cpp        </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "person.h"
  #include "school.h"
  
  int main() {
      person p;   
      school s;
      std::cout &lt;&lt; p.name &lt;&lt; std::endl;
      s.personVect.push_back(p);
      std::cout &lt;&lt; s.personVect.size() &lt;&lt; std::endl;
      std::cout &lt;&lt; s.personVect.at(0).name &lt;&lt; std::endl;
      p.test();
      return 0;
  }
  </code></pre>
  
  <p>school.h</p>
  
  <pre><code>#ifndef SCHOOL_H
  #define SCHOOL_H
  #include &lt;vector&gt;
  #include "person.h"
  
  class school
  {
  public:
      school();
      ~school();
  
      std::vector&lt;person&gt; personVect;
  
  
  };
  
  #endif // SCHOOL_H
  </code></pre>
  
  <p>school.cpp</p>
  
  <pre><code>#include "school.h"    
  school::school(){}    
  school::~school(){}
  </code></pre>
  
  <p>person.h</p>
  
  <pre><code>#ifndef PERSON_H
  #define PERSON_H
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include "school.h"
  
  
  class person {
  public:
  
      std::string name;
      std::string phone;
  
      school doSomethingWithSchool();
  
      void test();
  
      person();
      ~person();
  
  };
  
  #endif // PERSON_H
  </code></pre>
  
  <p>person.cpp</p>
  
  <pre><code>#include "person.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  person::person()
  {
      name = "marcus";
      phone = "0400000000";
  }
  
  person::~person()
  {
  }
  
  void person::test() {
      cout &lt;&lt; this-&gt;name;
  }
  school person::doSomethingWithSchool() {
      school s; 
  }
  </code></pre>