title: C++ - Build Order and Dependency Problem
body: <p>I seem to be misunderstanding something related to build order dependencies in C++.  So I have this code, which defines a class that I use as a functionoid (object whose purpose is to substitute for passing a function pointer):</p>
  
  <pre><code>#include "Imports.h"
  
  class X: public Y
  {
  public:
  
      X (T* t) { this-&gt;t= t; }
      virtual ~X(){}
  
      virtual void draw()
      {
          if (t-&gt;booleanReturningFunction())
          {
                  t-&gt;someField.draw();
          }
      }
  
      T* t;
  };
  </code></pre>
  
  <p>I'm getting a compiler error that complains about the "use of undefined type T" at the line numbers where I'm using T.  However, Imports.h looks like:</p>
  
  <pre><code>//The goal of this file is to have all the typcally needed imports in one place.
  
  #if !defined(IMPORTS_H)
  #define IMPORTS_H
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;iostream&gt;
  #include &lt;assert.h&gt;
  #include &lt;cmath&gt;
  #include &lt;fstream&gt;
  
  class T;
  class X;
  class Y;
  
  #include "Y.h"
  #include "X.h"
  #include "T.h"
  
  #endif // if !defined(IMPORTS_H)
  </code></pre>
  
  <p>With each ".h" file containing a definition of that class.  Now T actually does have an X object in it (not a pointer, but an X object).  But, as far as I can tell, there's no circular dependency in the build order because X only has a pointer to T, right?  Is there anything I'm missing that you can see just from this code?  Help is much appreciated!</p>
  
  <p><strong>Edit:</strong> I solved my problem. The issue was that I was doing the above code inside a header file. The compiler understandably couldn't compile t->booleanReturningFunction() based on a forward reference (it needed to see the class declaration to know what address to bind the function call to). </p>