title: Invalid use of incomplete type (class)
body: <p>I am getting a few errors in my Binary Search Tree print code and I do not know why.  (Errors at the bottom)</p>
  
  <pre><code>#ifndef MYBSTREE_H
  #define MYBSTREE_H
  
  #include "abstractbstree.h"
  #include "abstractstack.h"
  using namespace std;
  
  class LinkedStack *head = NULL;           //LINE 7
  
  template&lt;typename T&gt;
  class TreeNode
  {
    public:
      T m_data;
      TreeNode* m_right;
      TreeNode* m_left;
  
  };
  
  
  template&lt;typename T&gt;
  class LinkedStack: public AbstractStack&lt;TreeNode&lt;T&gt;*&gt;
  {
    public:
      TreeNode&lt;T&gt;* m_data;
      LinkedStack *m_next;
  
      LinkedStack()
      {
        if(head != NULL)
          head = new LinkedStack;
        m_data = 0;
        m_next = NULL;
      }
  
      void clear()
      {
        while(head -&gt; m_next != NULL)
        {
          LinkedStack *tmp = head -&gt; m_next;
          head -&gt; m_ldata= tmp -&gt; m_ldata;
          head -&gt; m_next = tmp -&gt; m_next;
          delete tmp;
        }
      }
  
  
      void push(TreeNode&lt;T&gt;* x)
      {
        LinkedStack *tmp = new LinkedStack;
        tmp -&gt; m_data = m_data;
        tmp -&gt; m_next = m_next;
        m_data = x;
        m_next = tmp;
      }
  
      void pop()
      {
        if (isEmpty())
          cout&lt;&lt;"Panic! Nothing to pop"&lt;&lt;endl;
        else
        {
          LinkedStack *tmp;
          tmp = m_next;
          m_data = tmp -&gt; m_data;
          m_next = tmp -&gt; m_next;
          delete tmp;
        }
      }
  
      int&amp; top()
      {
        if (isEmpty())
          cout&lt;&lt;"Panic! List is Empty"&lt;&lt;endl;
  
          return m_ldata;
      }
  
      bool isEmpty()
      {
        bool empty = false;
  
        if (m_next == NULL)
        {
          empty = true;
        }
  
        return empty;
      }
  };
  
  template&lt;typename T&gt;
  class MyBSTree:public AbstractBSTree&lt;T&gt;
  {
    private:
  
      TreeNode&lt;T&gt;* m_root;
  
    public:
  
      ~MyBSTree()  
      {
        clear();
      }
  
      MyBSTree()
      {
        m_root -&gt; m_data = T();
        m_root -&gt; m_right = NULL;
        m_root -&gt; m_left = NULL;
      };
  
      int size() const
      {
          if(m_root==NULL)
            return 0;
          else
            return (size(m_root-&gt;m_left)+1+size(m_root-&gt;m_right));
      }
  
      bool isEmpty() const
      {
        if (m_root== NULL)
          return true;
  
        else
          return false;
      }
  
      int height() const
      {
        int lh,rh;
        if(m_root==NULL)
        {
          return 0;
        }
        else
        {
          lh = height(m_root-&gt;m_left);
          rh = height(m_root-&gt;m_right);
  
          if(lh &gt; rh)
            return lh + 1;
          else
            return rh + 1;
        }
      }
  
      const T&amp; findMax() const
      {
        TreeNode&lt;T&gt;* p = m_root;
        while(p -&gt; m_right != NULL)
          p = p -&gt; m_right;
        return p;
      }
  
      const T&amp; findMin() const
      {
        TreeNode&lt;T&gt;* p = m_root;
        while(p -&gt; m_left != NULL)
          p = p -&gt; m_left;
        return p;
      }
  /*
      int contains(const T&amp; x) const;
  */
      void clear()
      {
        delete m_root;
      }
  
      void insert(const T&amp; x)
      {
        TreeNode&lt;T&gt;* p = m_root;
  
        do
        {  
          if (x == p -&gt; m_root)
            return;
          else if ( x &lt; p-&gt;m_data)
          {
            if(p-&gt;m_left == NULL)
            {
                p-&gt;m_left = new TreeNode&lt;T&gt;;
                p -&gt; m_left -&gt; m_data = x;
                return;
            }
            else
              p = p -&gt; m_left;
          }
          else if( x &gt; p-&gt;m_data)
          {
            if(p-&gt;m_right == NULL)
            {
              p-&gt;m_right = new TreeNode&lt;T&gt;;
              p-&gt; m_right -&gt; m_data = x;
              return;
            }
            else
              p = p -&gt; m_right;
          } 
        }while(p -&gt; m_right != NULL &amp;&amp; p -&gt; m_left != NULL);
      }
  
      void remove(const T&amp; x)
      {
          if(m_root == NULL)
              return;
  
          TreeNode&lt;T&gt;* q = m_root;
          TreeNode&lt;T&gt;* p;
  
          while(q != NULL)
          {
              if(m_root-&gt;m_data == x)
              {
                  delete q;
                  return;
              }
              else if(x &gt; q-&gt;m_data)
              {
                  p = q; 
                  q = q-&gt;m_right;
              }
              else
              {
                  p = q; 
                  q = q-&gt;m_left;            
              }
          }
  
          if(q-&gt;m_left == NULL &amp;&amp; q-&gt;m_right == NULL)
          {
              if(p == q)
                  delete p;
              else if(p-&gt;m_left == q)
              {
                  p-&gt;m_left = NULL;
                  delete q;
              }
              else 
              {
                  p-&gt;m_right = NULL;
                  delete q;
              }
              return;
          }
  
          if((q-&gt;m_left == NULL &amp;&amp; q-&gt;m_right != NULL) || (q-&gt;m_left != NULL &amp;&amp; q-&gt;m_right == NULL))
          {
              if(q-&gt;m_left == NULL &amp;&amp; q-&gt;m_right != NULL)
              {
                  if(p-&gt;m_left == q)
                  {
                      p-&gt;m_left = q-&gt;m_right;
                      delete q;
                  }
                  else
                  {
                      p-&gt;m_right = q-&gt;m_right;
                      delete q;
                  }
              }
              else
              {
                  if(p-&gt;m_left == q)
                  {
                      p-&gt;m_left = q-&gt;m_left;
                      delete q;
                  }
                  else
                  {
                      p-&gt;m_right = q-&gt;m_left;
                      delete q;
                  }
              }
              return;
          }
  
          if (q-&gt;m_left != NULL &amp;&amp; q-&gt;m_right != NULL)
          {
              TreeNode&lt;T&gt;* check;
              check = q-&gt;m_right;
              if((check-&gt;m_left == NULL) &amp;&amp; (check-&gt;m_right == NULL))
              {
                  q = check;
                  delete check;
                  q-&gt;m_right = NULL;
              }
              else
              {
                  if((q-&gt;m_right)-&gt;m_left != NULL)
                  {
                      TreeNode&lt;T&gt;* m_leftq;
                      TreeNode&lt;T&gt;* m_leftp;
                      m_leftp = q-&gt;m_right;
                      m_leftq = (q-&gt;m_right)-&gt;m_left;
                      while(m_leftq-&gt;m_left != NULL)
                      {
                          m_leftp = m_leftq;
                          m_leftq = m_leftq-&gt;m_left;
                      }
                      q-&gt;data = m_leftq-&gt;data;
                      delete m_leftq;
                      m_leftp-&gt;m_left = NULL;
                  }
                  else
                  {
                      TreeNode&lt;T&gt;* tmp;
                      tmp = q-&gt;m_right;
                      q-&gt;data = tmp-&gt;data;
                      q-&gt;m_right = tmp-&gt;m_right;
                      delete tmp;
                  }
              }
              return;
          }
      }
  
      void printPreOrder() const
      {
        LinkedStack stack;
        stack&lt;T&gt;.push(m_root);                           //THIS LINE
        while(!stack.isEmpty())                          //THIS LINE
          {
            TreeNode&lt;T&gt;* root = stack.push();        //THIS LINE
            stack.pop();                             //THIS LINE
            if(root!= NULL)
            {
              stack.push(root-&gt;right);           //THIS LINE
              stack.push(root-&gt;m_left);          //THIS LINE
              cout &lt;&lt; root-&gt;m_data &lt;&lt; " ";
            }
  
          }
  
      }
  /*
      void printPostOrder() const;
  
      void print() const;
      */
  };
  
  
  #endif
  </code></pre>
  
  <p>What I am getting are errors that say:</p>
  
  <pre><code>MyBSTree.h: In member function âvoid MyBSTree&lt;T&gt;::printPreOrder() constâ:
  MyBSTree.h:362:9: error: invalid use of incomplete type âstruct LinkedStackâ
  MyBSTree.h:7:7: error: forward declaration of âstruct LinkedStackâ
  </code></pre>
  
  <p>I get that for all the lines I have marked in that particular function.  I'm pretty sure it has something to do with template syntax, but I'm not sure.</p>