title: Defining Classes that Contain Pointers to Each Other
body: <p>I have a series of classes in C++ that contain pointers to each other for interconnection reasons. The code is as follows:</p>
  
  <pre><code>class Cell;
  
  //classes
  class Connection {
  public:
      Cell * source;
  
      virtual bool trigger() {
          return source-&gt;trigger();  //line 16, source of the error
      }
  
      //constructors
      //default
      Connection() {
          source = NULL;
      }
  
      //call
      Connection(Cell * in) {
          source = in;
      }
  
      //copy
      Connection(const Connection &amp; in) {
          source = in.source;
      }
  };
  
  class NotConnection : Connection {
  public:
      virtual bool trigger() override {
          return !source-&gt;trigger();
      }
  
      //constructors
      //default
      NotConnection() {
          source = NULL;
      }
  
      //call
      NotConnection(Cell * in) {
          source = in;
      }
  
      //copy
      NotConnection(const NotConnection &amp; in) {
          source = in.source;
      }
  };
  
  
  class Cell {
  public:
      vector&lt;Connection *&gt; parents;
  
      virtual bool trigger() = 0;
  
      ~Cell() {
          for (int i = 0; i &lt; parents.size(); i++) {
              delete parents[i];
          }
      }
  };
  </code></pre>
  
  <p>I thought I could use forward declaration to clear up any compilation issues but when I attempt to build the project I get the error:</p>
  
  <pre><code>source.cpp(16): error C2027: use of undefined type 'Cell'
  </code></pre>
  
  <p>I tried re-ordering the classes and forward declaring <code>Connection</code> instead and that did not work either, my question is why is the compiler throwing this error and what can I do to resolve it?</p>