Newsgroup: it.comp.lang.c++
Titolo: help with visual c++

I cannot figure out two errors that I am coming up with.  Could somone take
a look and give some advice or hints.  Thanks in advance.
Errors are:
--------------------Configuration: BST - Win32 Debug--------------------
Compiling...
BST.cpp
C:\Documents and Settings\TJ\Desktop\Programming\BST.cpp(151) : error C2244:
'Search_tree<Record>::search_for_node' : unable to resolve function overload
C:\Documents and Settings\TJ\Desktop\Programming\BST.cpp(154) : error C2954:
template definitions cannot nest
Error executing cl.exe.
BST.obj - 2 error(s), 0 warning(s)
This is my source code:
#include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
using namespace std;
enum Error_code{success, failure, underflow, overflow, empty,
duplicate_error};
template <class Entry>
struct Binary_node {
//    data members:
   Entry data;
   Binary_node<Entry> *left;
   Binary_node<Entry> *right;
//    constructors:
   Binary_node();
   Binary_node(const Entry &x);
};
template <class Entry>
Binary_node<Entry>::Binary_node(const Entry &x)
{
 data=x;
 left=NULL;
 right=NULL;
}
//----------------------------BT code------------------------
template <class Entry>
class Binary_tree {
public:
   Binary_tree();
   bool empty() const;
   void inorder(void (*visit)(Entry &));
   void A(void (*visit)(Entry &));
   void insert(const Entry &);
   Binary_tree (const Binary_tree<Entry> &original);
   Binary_tree & operator =(const Binary_tree<Entry> &original);
   //~Binary_tree();
protected:
   Binary_node<Entry> *root;
   void recursive_inorder(Binary_node<Entry> *sub_root,void (*visit)(Entry
&));
};
template <class Entry>
Binary_tree<Entry>::Binary_tree()
/*
Post: An empty binary tree has been created.
*/
{
   root = NULL;
}
template <class Entry>
bool Binary_tree<Entry>::empty() const
/*
Post: A result of true is returned if the binary tree is empty.
      Otherwise, false is returned.
*/
{
   return root == NULL;
}
template <class Entry>
void Binary_tree<Entry>::inorder(void (*visit)(Entry &))
/*
Post: The tree has been traversed in inorder sequence.
Uses: The function recursive_inorder
*/
{
   recursive_inorder(root, visit);
}
template <class Entry>
void Binary_tree<Entry>::recursive_inorder(Binary_node<Entry> *sub_root,
                                           void (*visit)(Entry &))
/*
Pre:  sub_root is either NULL or points to a subtree of the Binary_tree.
Post: The subtree has been traversed in inorder sequence.
Uses: The function recursive_inorder recursively
*/
{
   if (sub_root != NULL) {
      recursive_inorder(sub_root->left, visit);
      (*visit)(sub_root->data);
      recursive_inorder(sub_root->right, visit);
   }
}
template <class Entry>
void Binary_tree<Entry>::A(void (*visit)(Entry &))
{
  if (root != NULL) {
    (*visit)(root->data);
    root->left.B(visit);
    root->right.B(visit);
  }
}
template <class Record>
class Search_tree: public Binary_tree<Record> {
public:
   Error_code insert(const Record &new_data);
   Error_code remove(const Record &old_data);
   Error_code tree_search(Record &target) const;
 private: //  Add auxiliary function prototypes here.
   Error_code search_and_destroy(Binary_node<Record>* &sub_root, const
Record &target);
   Error_code remove_root(Binary_node<Record> *&sub_root);
   Error_code search_and_insert(Binary_node<Record> *&sub_root, const Record
&new_data);
   Binary_node search_for_node(Binary_node<Record> *sub_root, const Record
&target) const;
};
template <class Record>
Error_code Search_tree<Record>::tree_search(Record &target) const
/*
Post: If there is an entry in the tree whose key matches that in target,
      the parameter target is replaced by the corresponding record from
      the tree and a code of success is returned.  Otherwise
      a code of not_present is returned.
Uses: function search_for_node
*/
{
   Error_code result = success;
   Binary_node<Record> *found = search_for_node(root, target);
   if (found == NULL)
      result = not_present;
   else
      target = found->data;
   return result;
}
template <class Record>
Binary_node<Record> *Search_tree<Record>::search_for_node(
            Binary_node<Record> *sub_root, const Record &target) const
{
   while (sub_root != NULL && sub_root->data != target)
      if (sub_root->data < target) sub_root = sub_root->right;
      else sub_root = sub_root->left;
   return sub_root;
}
template <class Record>
Error_code Search_tree<Record>::insert(const Record &new_data)
{
   return search_and_insert(root, new_data);
}
template <class Record>
Error_code Search_tree<Record>::search_and_insert(
           Binary_node<Record> *&sub_root, const Record &new_data)
{
   if (sub_root == NULL) {
      sub_root = new Binary_node<Record>(new_data);
      return success;
   }
   else if (new_data < sub_root->data)
      return search_and_insert(sub_root->left, new_data);
   else if (new_data > sub_root->data)
      return search_and_insert(sub_root->right, new_data);
   else return duplicate_error;
}
template <class Record>
Error_code Search_tree<Record>::remove_root(Binary_node<Record>
                                            *&sub_root)
/*
Pre:  sub_root is either NULL or points to a subtree of the Search_tree.
Post: If sub_root is NULL, a code of not_present is returned.
      Otherwise, the root of the subtree is removed in such a way
      that the properties of a binary search tree are preserved.
      The parameter sub_root is reset as the root of the modified subtree,
      and success is returned.
*/
{
   if (sub_root == NULL) return not_present;
   Binary_node<Record> *to_delete = sub_root;  //  Remember node to delete
at end.
   if (sub_root->right == NULL) sub_root = sub_root->left;
   else if (sub_root->left == NULL) sub_root = sub_root->right;
   else {                           //  Neither subtree is empty.
      to_delete = sub_root->left;   //  Move left to find predecessor.
      Binary_node<Record> *parent = sub_root; //  parent of to_delete
      while (to_delete->right != NULL) { //  to_delete is not the
predecessor.
         parent = to_delete;
         to_delete = to_delete->right;
      }
      sub_root->data = to_delete->data;  //  Move from to_delete to root.
      if (parent == sub_root) sub_root->left = to_delete->left;
      else parent->right = to_delete->left;
   }
   delete to_delete;   //  Remove to_delete from tree.
   return success;
}
template <class Record>
Error_code Search_tree<Record>::remove(const Record &target)
/*
Post: If a Record with a key matching that of target belongs to the
      Search_tree, a code of success is returned, and the corresponding node
      is removed from the tree.  Otherwise, a code of not_present is
returned.
Uses: Function search_and_destroy
*/
{
   return search_and_destroy(root, target);
}
template <class Record>
Error_code Search_tree<Record>::search_and_destroy(
           Binary_node<Record>* &sub_root, const Record &target)
/*
Pre:  sub_root is either NULL or points to a subtree of the Search_tree.
Post: If the key of target is not in the subtree, a code of not_present
      is returned.  Otherwise, a code of success is returned and the subtree
      node containing target has been removed in such a way that
      the properties of a binary search tree have been preserved.
Uses: Functions search_and_destroy recursively and remove_root
*/
{
   if (sub_root == NULL || sub_root->data == target)
      return remove_root(sub_root);
   else if (target < sub_root->data)
      return search_and_destroy(sub_root->left, target);
   else
      return search_and_destroy(sub_root->right, target);
}
template <class Entry>
void PrintData(Entry &x);
main()
{
 Search_tree<int> t1;
 t1.insert(5);
 t1.insert(3);
 t1.insert(7);
 t1.insert(8);
 t1.insert(6);
 t1.insert(1);
 t1.insert(2);
    t1.inorder(PrintData<int>);
 int x=3;
 int y=4;
// t1.tree_search(x);
// t1.tree_search(y);
    cout<<"might be working";
 return 0;
}
template <class Entry>
void PrintData(Entry &x)
{
 cout<<x<<"\n";
}

Could someone please help me figure out these errors.
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
c:\documents and settings\tj\desktop\programming\test.cpp(115) : error
C2244: 'Search_tree<Record>::search_for_node' : unable to resolve function
overload
c:\documents and settings\tj\desktop\programming\test.cpp(118) : error
C2954: template definitions cannot nest
Error executing cl.exe.
test.obj - 2 error(s), 0 warning(s)

using namespace std;




   void inorder(void (*visit)(Entry &));
   Binary_tree (const Binary_tree<Entry> &original);
   Binary_tree & operator =(const Binary_tree<Entry> &original);
protected:
   Binary_node<Entry> *root;
   void recursive_inorder(Binary_node<Entry> *sub_root,void (*visit)(Entry
&));
};
template <class Entry>
Binary_tree<Entry>::Binary_tree()
/*
Post: An empty binary tree has been created.
*/
{
   root = NULL;
}
template <class Entry>
void Binary_tree<Entry>::recursive_inorder(Binary_node<Entry> *sub_root,
                                           void (*visit)(Entry &))
/*
Pre:  sub_root is either NULL or points to a subtree of the Binary_tree.
Post: The subtree has been traversed in inorder sequence.
Uses: The function recursive_inorder recursively
*/
{
   if (sub_root != NULL) {
      recursive_inorder(sub_root->left, visit);
      (*visit)(sub_root->data);
      recursive_inorder(sub_root->right, visit);
   }
}
template <class Record>
class Search_tree: public Binary_tree<Record> {
public:
   Error_code insert(const Record &new_data);
   Error_code tree_search(Record &target) const;
 private: //  Add auxiliary function prototypes here.

};




