title: c++ templated friend class
body: <p>I'm trying  to write an implementation of a 2-3-4 tree in c++. I'm it's been a while since I've used templates, and I'm getting some errors. Here's my extremely basic code framework:<br>
      node.h:</p>
  
  <pre><code>    #ifndef TTFNODE_H  
      #define TTFNODE_H  
      template &lt;class T&gt;  
      class TreeNode  
      {  
        private:  
        TreeNode();  
        TreeNode(T item);  
        T data[3];  
        TreeNode&lt;T&gt;* child[4];  
        friend class TwoThreeFourTree&lt;T&gt;;   
        int nodeType;  
      };  
      #endif
  </code></pre>
  
  <p>node.cpp:</p>
  
  <pre><code>#include "node.h"
  
  using namespace std;
  template &lt;class T&gt;
  //default constructor
  TreeNode&lt;T&gt;::TreeNode(){
  }
  
  template &lt;class T&gt;
  //paramerter receving constructor
  TreeNode&lt;T&gt;::TreeNode(T item){
  data[0] = item;
  nodeType = 2;
  }
  </code></pre>
  
  <p>TwoThreeFourTree.h</p>
  
  <pre><code>#include "node.h"
  #ifndef TWO_H
  #define TWO_H
  enum result {same, leaf,lchild,lmchild,rmchild, rchild};
  template &lt;class T&gt; class TwoThreeFourTree
  {
    public:
      TwoThreeFourTree();
  
    private:
      TreeNode&lt;T&gt; * root;
  };
  #endif
  </code></pre>
  
  <p>TwoThreeFourTree.cpp:</p>
  
  <pre><code>#include "TwoThreeFourTree.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  template &lt;class T&gt;
  TwoThreeFourTree&lt;T&gt;::TwoThreeFourTree(){
    root = NULL;
  }
  </code></pre>
  
  <p>And main.cpp:</p>
  
  <pre><code>#include "TwoThreeFourTree.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(){
    ifstream inFile;
    string filename = "numbers.txt";
    inFile.open (filename.c_str());
    int curInt = 0;
    TwoThreeFourTree &lt;TreeNode&gt; Tree;
  
    while(!inFile.eof()){
      inFile &gt;&gt; curInt;
      cout &lt;&lt; curInt &lt;&lt; " " &lt;&lt; endl;
    }
  
    inFile.close();
  }
  </code></pre>
  
  <p>And when I try to compile from the command line with:
       g++ main.cpp node.cpp TwoThreeFourTree.cpp</p>
  
  <p>I get the following errors:  </p>
  
  <pre><code>In file included from TwoThreeFourTree.h:1,  
               from main.cpp:1:  
  node.h:12: error: ‘TwoThreeFourTree’ is not a template  
  main.cpp: In function ‘int main()’:  
  main.cpp:13: error: type/value mismatch at argument 1 in template parameter list for ‘template&lt;class T&gt; class TwoThreeFourTree’  
  main.cpp:13: error:   expected a type, got ‘TreeNode’  
  main.cpp:13: error: invalid type in declaration before ‘;’ token  
  In file included from node.cpp:1:  
  node.h:12: error: ‘TwoThreeFourTree’ is not a template  
  In file included from TwoThreeFourTree.h:1,  
               from TwoThreeFourTree.cpp:1:  
  node.h:12: error: ‘TwoThreeFourTree’ is not a template  
  </code></pre>
  
  <p>My main question is why it's saying "error: ‘TwoThreeFourTree’ is not a template". Does anyone have any ideas? Thanks for all advice/help in advance...
  Dan</p>