title: Invalid use of non-static data member while using templates
body: <p>I have the following code snipped, which implements a Binary Search Tree with templates:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  template&lt;typename T&gt;
  class Node{
      public:
      T data;
      Node&lt;T&gt; *left;
      Node&lt;T&gt; *right;
      Node&lt;T&gt; *parent;
  
      Node(T input_data=NULL){
          data=input_data;
          left=NULL;
          right=NULL;
          parent =NULL;    
      }
  };
  
  
  
  template&lt;typename T&gt;
  class BinarySearchTree{
      private:
      long n;
      Node&lt;T&gt; *root;
  
  
      public:
      BinarySearchTree(Node&lt;T&gt; *input_root=NULL, long input_size=0){
          n=input_size;
          root=input_root;
      } 
  
      void insert(Node&lt;T&gt; *p=root, T  data){
          Node&lt;T&gt; *par=NULL;
          while(p!=NULL){
              par=p;
              if(data &lt;= p-&gt;data)
                  p=p-&gt;left;
              else 
                  p=p-&gt;right;
          }
          Node&lt;T&gt; *z=new Node&lt;T&gt;(data);
          if(root==NULL){
              root=z;
              n=1;
              return;
          }
          z-&gt;parent=par;
          if(data&lt;=par-&gt;data)
              par-&gt;left=z;
          else
              par-&gt;right=z;
  
          n+=1;                
      }
  
      void inorder(Node&lt;T&gt; *p=root){
          if(p){
              inorder(p-&gt;left);
              cout&lt;&lt;p-&gt;data&lt;&lt;" ";
              inorder(p-&gt;right);
          }
      }
  
  int main(){
      BinarySearchTree&lt;int&gt; *t=new BinarySearchTree&lt;int&gt;();
      t-&gt;insert(5);
      t-&gt;insert(15);
      t-&gt;insert(3);
      t-&gt;insert(14);
      t-&gt;insert(25);
      t-&gt;insert(10);
      t-&gt;inorder();
  
  }
  </code></pre>
  
  <p>There's a compilation error on line 27, (i.e. Node *root;), and which reads: "Invalid use of non-static data member 'BinarySearchTree::root'". I think it has to do with the default arguments that I've included have in the functions 'insert' and 'inorder', because I don't get the error when I remove the default argument 'root'.</p>
  
  <p>My question is, what is happening and how do I get around it? I would like to preserve the default argument of root if that's possible.</p>
  
  <p>If it matters, I'm using a software called '<a href="http://www.codecutter.net/tools/quincy/" rel="nofollow">Quincy 2005</a>' on Windows 8.1 to compile (for certain reasons).</p>