title: error: Invalid use of incomplete type struct Subject; error: forward declaration of struct Subject
body: <p>I inheriting from a template class. When I make an entry in teacher class, I want to make an entry in subject class &amp; vice versa.
  I get an error Invalid use of incomplete type struct Subect;</p>
  
  <pre><code>void addSubject(Subject *s) {
              this-&gt;addReference(s);
              s-&gt;addReference(this); when I comment this line the it compiles without errors, but I cannot insert into Subject 
  
          }
  </code></pre>
  
  <p>My entire code is below</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  class Subject;
  
  
  template &lt;class T&gt;
  class abstractReference {
  
  
      vector&lt;T*&gt; list;
      public:
      string code;
          void addReference(  T*);
          void delReference(  T*);
          bool hasReference(  T*);
          T * getReference(int );
  };
  
  template &lt;class T&gt;
  void abstractReference&lt;T&gt;::addReference(T* ref) {
      list.push_back(ref);
      //ref-&gt;addReference(this);
  }
  
  template &lt;class T&gt;
  void abstractReference&lt;T&gt;::delReference(T* ref) {
      int i;
      for (i=0; i&lt;list.size(); i++) {
          if (list[i]== ref) list.erase(i);
      }
  
  }
  
  template &lt;class T&gt;
  bool abstractReference&lt;T&gt;::hasReference( T* ref) {
    if (list.size() == 0) return false;
    int i;
    for (i=0; i&lt;list.size(); i++) {
        if (list[i] == ref) return true;
    }
    return false;
  }
  
  template &lt;class T&gt;
  T* abstractReference&lt;T&gt;::getReference(int i) {
      if (i &lt; 0 || i &gt; list.size()) return NULL;
      return list[i];
  }
  
  class Teacher : public abstractReference&lt;Subject&gt; {
  
      string fname;
      string lname;
      float  sal;
  public:
      Teacher(string c, string fn, string ln, float s): fname(fn), lname(ln), sal(s) {
      }
      Teacher() {sal =0; fname=""; lname="";}
      void setInfo(string c, string fn, string ln, float s=0.00) {
          code=c;
          fname = fn;
          lname = ln;
          sal = s;
      }
  
      string getName() {
          return fname + " " + lname;
      }
  
      float getSal() {
          return sal;
      }
  
      void addSubject(Subject *s) {
          this-&gt;addReference(s);
          s-&gt;addReference(this);
  
      }
  
      void delSubject(Subject *s) {
  
      }
  
  };
  
  class Subject : public abstractReference&lt;Teacher&gt; {
    string title;
  public:
    Subject(string c=NULL, string t=NULL) {
        title = t;
  
    }
    string getTitle() {
        return title;
    }
  };
  
  main() {
      Teacher *t;
      t = new Teacher("J109", "Dexter", "McConnell",15000);
      Subject *s, *s1, *s2;
      s= new Subject("E001", "English");
      s1= new Subject("M001", "Maths");
      s2= new Subject("s001", "Science");
  
      t-&gt;addSubject(s);
      t-&gt;addSubject(s1);
  
      cout &lt;&lt; "Has Reference " &lt;&lt; t-&gt;hasReference(s2) &lt;&lt; endl;
      cout &lt;&lt; "Done..." &lt;&lt; endl;
      cout &lt;&lt; t-&gt;getReference(1)-&gt;getTitle() &lt;&lt; endl;
  }
  </code></pre>