title: Binary Search Tree error converting from template to const int
body: <p>I am doing homework and I am try to implement some binary search tree functions. I am also very new to programming, and do not have much experience with programming. I have the functions written out, but I am tring to figure out the error that I am receiving. The error that I am receiving is <code>btree.h(76): error C2664: 'Node&lt;T&gt;::find_node' : cannot convert parameter 1 from 'Node&lt;T&gt; *' to 'const int &amp;'
            with
            [
                T=int
            ]
            Reason: cannot convert from 'Node&lt;T&gt; *' to 'const int'
            with
            [
                T=int
            ]</code></p>
  
  <p>This is the reason why I put the cpp files as well. Get an error in the cpp files as well. All files were provided by my professor. I only had to add 2 methods to node.h, and that was it. This is the error in the cpp file tree2.cpp</p>
  
  <p><code>tree2.cpp(28) : see reference to class template instantiation 'BinaryTree&lt;elemType&gt;' being compiled
            with
            [
               elemType=int
           ]</code></p>
  
  <p>If anyone could help out explain how to fix the error with suggestions would be great. </p>
  
  <p>btree.h</p>
  
  <pre><code>#include    &lt;iostream&gt;
  #include    "node.h"
  //using namespace std;
  
  template &lt; typename elemType &gt;
  class BinaryTree {
    public:
  BinaryTree( );
  ~BinaryTree( );
  void insert( const elemType &amp; );
  void remove( const elemType &amp; );
  void inorder( );
  bool empty( );
  void clear( );
  
  private:
  Node&lt; elemType &gt;    *_root;
  
  BinaryTree( const BinaryTree &amp; );
  BinaryTree &amp;operator =( const BinaryTree &amp; );
  void clear( Node&lt; elemType &gt; * );
  };
  
  template &lt; typename elemType &gt;
  inline BinaryTree&lt; elemType &gt;::BinaryTree( ) : _root(0)
  {
      cout &lt;&lt; "BinaryTree::BinaryTree() "
         &lt;&lt; "default constructor\n";
  }
  
  template &lt; typename elemType &gt;
  inline BinaryTree&lt; elemType &gt;::~BinaryTree( )
  {
     cout &lt;&lt; "BinaryTree::~BinaryTree() destructor\n";
     clear( );
  }
  
  template &lt; typename elemType &gt;
  inline void BinaryTree&lt; elemType &gt;::clear( )
  {
     if( _root )
     {
        clear( _root );
        _root = 0;
     }
  }
  
  template &lt; typename elemType &gt;
  inline void BinaryTree&lt; elemType &gt;::clear( Node&lt; elemType &gt; *pt )
  {
     if( pt ) {
        cout &lt;&lt; "clear( ) left of  "  &lt;&lt; pt-&gt;value( ) &lt;&lt; '\n';
        clear( pt-&gt;left( ) );
        cout &lt;&lt; "clear( ) right of " &lt;&lt; pt-&gt;value( ) &lt;&lt; '\n';
        clear( pt-&gt;right( ) );
        delete pt;
      }
  }
  
  template &lt; typename elemType &gt;
  inline void BinaryTree&lt; elemType &gt;::insert( const elemType &amp;e )
  {
     if( !_root )
     {
        _root = new Node&lt; elemType &gt;( e );
     }
     else
     {
        _root-&gt;insert_value( e );
     }
  }
  
  template &lt; typename elemType &gt;
  inline void BinaryTree&lt; elemType &gt;::remove( const elemType &amp;e )
  {
    _root-&gt;find_node( _root, e );
  }
  
  template &lt; typename elemType&gt;
  inline void BinaryTree&lt; elemType &gt;::inorder( )
  {
     _root-&gt;inorder( _root );
     cout &lt;&lt; '\n';
  }
  </code></pre>
  
  <p><code>node.h</code></p>
  
  <pre><code>#ifndef     NODE_H
  
  #define     NODE_H
  
  #include    &lt;string&gt;
  
  using namespace std;
  
  template&lt; typename T &gt;
  class Node
  {
    public:
        Node( const T &amp;);
  
        T  value( )  const;
        T  value( const T &amp; );
  
        void insert_value( const T &amp; );
        void inorder( const Node * );
        void find_node( const T &amp;val, const T* root );
      //bool find_node( const T &amp;val, Node &lt; T &gt; *node) const;
        void delete_node( Node&lt; T &gt; *&amp;p );
  
        Node *  left ( ) const;
        Node *  left ( Node * );
        Node *  right( ) const;
        Node *  right( Node * );
  
     private:
        T       _value;
        Node *  _left;
        Node *  _right;
        Node&lt; T &gt; * root; //point to root node
        Node::Node( const Node &amp; );
        Node &amp;operator =( const Node &amp; );
  
  
  
  };
  
  
  template&lt; typename T &gt;
  inline Node&lt; T &gt;::Node( const T &amp;rhs )
  {
     _value = rhs;                       // assign rhs to _value
     _left  =  _right = 0;               // node is not part of a tree yet
  }
  
  
  template&lt; typename T &gt;
  inline T Node&lt; T &gt;::value( ) const
  {
     return _value;
  }
  
  
  template&lt; typename T &gt;
  inline T Node&lt; T &gt;::value( const T &amp;rhs )
  {
     _value = rhs;                       // new value for _value
     return _value;
  }
  
  
  template&lt; typename T &gt;
  inline Node&lt; T &gt; *Node&lt; T &gt;::left( ) const
  {
     return _left;
  }
  
  
  template&lt; typename T &gt;
  inline Node&lt; T &gt; *Node&lt; T &gt;::left( Node&lt; T &gt; *rhs )
  {
     _left = rhs;
  
     return _left;
  }
  
  
  template&lt; typename T &gt;
  inline Node&lt; T &gt; *Node&lt; T &gt;::right( ) const
  {
     return _right;
  }
  
  
  template&lt; typename T &gt;
  inline Node&lt; T &gt; *Node&lt; T &gt;::right( Node&lt; T &gt; *rhs )
  {
     _right = rhs;
     return _right;
  }
  
  
  template&lt; typename T &gt;
  inline void Node&lt; T &gt;::insert_value( const T &amp;val )
  {
      if( val == _value )
  {
      return;                     // value already in the tree
  }
  if( val &lt; _value )              // val should appear at the left
  {
      if( ! _left )               // no left subtree ?
      {                           // add new node here
          _left = new Node( val );
      }
      else                        // try the subtree
      {
          _left-&gt;insert_value( val );
      }
  }
  else                            // val should appear at the right
  {
      if( ! _right )              // no right subtree ?
      {                           // add new node here
          _right = new Node( val );
      }
      else                        // try the subtree
      {
          _right-&gt;insert_value( val );
      }
    }
  }
  
  
  template&lt; typename T &gt;
  inline void Node&lt; T &gt;::inorder( const Node&lt; T &gt; *pt )
  {
     if( pt )
     {
        inorder( pt-&gt;_left );
        cout &lt;&lt; std::hex &lt;&lt; pt-&gt;_left &lt;&lt; std::dec &lt;&lt; '\t';
        cout &lt;&lt; std::hex &lt;&lt; pt &lt;&lt; std::dec &lt;&lt; '\t';
        cout &lt;&lt; std::hex &lt;&lt; pt-&gt;_right &lt;&lt; std::dec &lt;&lt; '\t';
        cout &lt;&lt; pt-&gt;_value &lt;&lt; '\n';
        inorder( pt-&gt;_right );
     }
  }
  
  
  template &lt;typename T&gt;
  Node&lt;T&gt; const * find_node(const T &amp;val)
  {
     Node&lt;T&gt; const * curr = root;
     while( curr != 0 )
     {
        if (val == curr -&gt; _value)  {
         break;
      }
      else if (val &lt; curr -&gt; _value) {
          curr = curr -&gt; _left;
      |
      else {
          curr = curr -&gt; _right;
      }
  }
  return curr;
  }
  }
  
  template &lt;typename T &gt;
  inline void find_node( const T &amp; val, const T * root ) {
  Node&lt;T&gt; const * ptrFoundNode = find_node_pointer( val, root );
  if( ptrFoundNode ) {
      delete_node( ptrFoundNode, root );
    }
  }
  
  template&lt; typename T &gt;
  inline void Node&lt; T &gt;::delete_node(Node &lt; T &gt; *&amp;p)
  {
  
  Node&lt;T&gt; *curr, *prev, *temp;
     if (p == NULL) return;
     if (p-&gt;_left == NULL &amp;&amp; p-&gt;_right == NULL) {
      // no children - easy
      // *** if allowing counted duplicates:
      // ***    if (p-&gt;getCount() &gt; 1) (*p)--;
      // ***    else {
         temp = p;
         p = NULL;
         delete temp;
      }
   else if (p-&gt;_left == NULL) {
      // only a right child - still easy
      // *** if allowing counted duplicates:
      // ***    if (p-&gt;getCount() &gt; 1) (*p)--;
      // ***    else {
         temp = p;
         p = temp-&gt;_right;
         delete temp;
      }
   else if (p-&gt;_right == NULL) {
      // only a left child - still easy
      // *** if allowing counted duplicates:
      // ***    if (p-&gt;getCount() &gt; 1) (*p)--;
      // ***    else {
         temp = p;
         p = temp-&gt;_left;
         delete temp;
      }
   else {
      // two children - this is the hard case
      // use successor: once right, then as far left as possible
      // *** if allowing counted duplicates:
      // ***    if (p-&gt;getCount() &gt; 1) (*p)--;
      // ***    else {
         curr = p-&gt;_right;
         prev = NULL;
         while (curr-&gt;_left != NULL) {
             prev = curr;
             curr = curr-&gt;left;
         }
         p-&gt;data = curr-&gt;data;
         if (prev == NULL) p-&gt;_right = curr-&gt;_right;
         else prev-&gt;_left = curr-&gt;_right;
  
         delete curr;
     }
  }
  
  
  #endif
  </code></pre>
  
  <p><code>tree2.cpp</code></p>
  
  <pre><code>#include    "btree.h"
  #include    &lt;fstream&gt;
  #include    &lt;string&gt;
  
  using namespace std;
  
  
  ifstream get_ifs( )                             // get input file stream
  {
     string filename;                            // input file name
  
     cerr &lt;&lt; "name of file to read from? ";
     cin  &gt;&gt; filename;
  
     ifstream ifs( filename, ifstream::in );
     if( ! ifs )                                 // cannot open file infilen
     {
        cerr &lt;&lt; "cannot open input file '" &lt;&lt; filename &lt;&lt; "'\n";
        exit( 1 );
     }
  
     return ifs;                                 // return input file stream
  }
  
  
  int main()
  {
     BinaryTree&lt; int &gt; bt;
  
     bt.insert( 30 );
     bt.insert( 20 );
     bt.insert( 40 );
     bt.insert( 50 );
     bt.insert( 10 );
     bt.insert( 15 );
     bt.insert( 35 );
  
     cout &lt;&lt; "inorder traversal:\n";
     bt.inorder( );
  
     ifstream ifs = get_ifs( );
  
     string cmd;
     int    value;
  
     while( ifs &gt;&gt; cmd )
     {
        ifs &gt;&gt; value;
  
        cout &lt;&lt; cmd &lt;&lt; '\t' &lt;&lt; value &lt;&lt; '\n';
  
        if( cmd == "a" )
        {
            bt.insert( value );
        }
        else if( cmd == "d" )
        {
            bt.remove( value );
         }
        else
        {
            cout &lt;&lt; "invalid command '" &lt;&lt; cmd &lt;&lt; "' ignored...\n\n";
        }
  
        bt.inorder( );
        cout &lt;&lt; '\n';
     }
  
     return 0;
  }
  </code></pre>
  
  <p><code>tree1.cpp</code></p>
  
  <pre><code>#include    "btree.h"
  #include    &lt;fstream&gt;
  #include    &lt;string&gt;
  
  using namespace std;
  
  
  ifstream get_ifs( )                             // get input file stream
  {
     string filename;                            // input file name
  
     cerr &lt;&lt; "name of file to read from? ";
     cin  &gt;&gt; filename;
  
     ifstream ifs( filename, ifstream::in );
     if( ! ifs )                                 // cannot open file infilen
     {
        cerr &lt;&lt; "cannot open input file '" &lt;&lt; filename &lt;&lt; "'\n";
        exit( 1 );
     }
  
     return ifs;                                 // return input file stream
  }
  
  
  int main()
  {
     BinaryTree&lt; string &gt; bt;
  
     bt.insert( "Florida" );
     bt.insert( "California" );
     bt.insert( "Alabama" );
     bt.insert( "Mississippi" );
     bt.insert( "Georgia" );
     bt.insert( "Colorado" );
     bt.insert( "Idaho" );
     bt.insert( "Missouri" );
     bt.insert( "New York" );
  
     cout &lt;&lt; "inorder traversal:\n";
     bt.inorder( );
  
     ifstream ifs = get_ifs( );
  
     string cmd, value;
     while( ifs &gt;&gt; cmd )
     {
        ifs &gt;&gt; value;
  
        cout &lt;&lt; cmd &lt;&lt; '\t' &lt;&lt; value &lt;&lt; '\n';
  
        if( cmd == "a" )
        {
            bt.insert( value );
        }
        else if( cmd == "d" )
        {
            bt.remove( value );
        }
        else
        {
            cout &lt;&lt; "invalid command '" &lt;&lt; cmd &lt;&lt; "' ignored...\n\n";
        }
  
        bt.inorder( );
        cout &lt;&lt; '\n';
     }
  
     return 0;
  }
  </code></pre>