Hello,

I am getting the following error on line 96, and also for every function implementation below line 96. What do I need to add?

error: expected unqualified-id before 'void'

//Binary_tree class interface
template <class Entry>
class Binary_tree {
public:
   Binary_tree(){}  //constructor
   //Post: An empty binary tree has been created.

   bool empty() const;
   //Post: A result of true is returned if the binary tree is empty.
   //Otherwise, false is returned.

   void preorder(void (*visit)(Entry &));
   //Post: The tree has been traversed in preorder sequence.
   //Uses: The function recursive_preorder

   void inorder(void (*visit)(Entry &));
   //Post: The tree has been traversed in inorder sequence.
   //Uses: The function recursive_inorder

   void postorder(void (*visit)(Entry &));
   //Post: The tree has been traversed in postorder sequence.
   //Uses: The function recursive_postorder

   void level_order(void (*visit) (Entry &));
   //Post: The tree has been traversed in level order sequence.
   //Uses: STL queue class

   int size() const;
   //Post: Returns the number of nodes in the tree
   //Uses: The function recursive_size

   void clear();
   //Post: All nodes of tree have been deleted, root set to NULL
   //Uses:  The function recursive_clear

   int height() const;
   //Post: Returns the height of the tree,
	 //where empty tree has height 0, one-node
	 //tree has height 1, etc.
   //Uses: The function recursive_height

   void insert(const Entry &);
   //Pre:  Data of type Entry has been passed for insertion -
   //note that the prototype need not include parameter names,
   //only data types
   //Post: Parameter has been inserted into the shortest
   //subtree or into the left subtree if equal height
   //Uses: The function recursive_insert

   Binary_tree (const Binary_tree<Entry> &original);
   //copy constructor
   //Post: creates a deep copy of tree original
   //Uses:  The function recursive_copy

   Binary_tree & operator =(const Binary_tree<Entry> &original);
   // overloaded assignment operator
   //Post: The calling tree is reset as a deep copy of tree pointed to by original
   //Uses:  The function recursive_copy

   ~Binary_tree(){}   //destructor

protected:
   //Auxiliary function prototypes - MORE NEED TO BE ADDED
   void recursive_preorder(Binary_node<Entry> *sub_root,
                           void (*visit)(Entry &));

   void recursive_inorder(Binary_node<Entry> *sub_root,
                           void (*visit)(Entry &));

   void recursive_postorder(Binary_node<Entry> *sub_root,
                           void (*visit)(Entry &));

   Binary_node<Entry>* recursive_copy(Binary_node<Entry>* sub_root);
   //Pre: sub_root is NULL or points to a subtree of the Binary_tree
   //Post: returns a pointer to a deep copy of tree pointed to by sub_root



   //Single member variable
   Binary_node<Entry> *root;
};




template<class Entry>
bool Binary_tree<Entry>::empty() const
{
    bool boo;
    return boo;
}
//Post: A result of true is returned if the binary tree is empty.
//Otherwise, false is returned.

template<class Entry>
void Binary_tree<Entry>::void preorder(void (*visit)(Entry &))
{

}
//Post: The tree has been traversed in preorder sequence.
//Uses: The function recursive_preorder

template<class Entry>
void Binary_tree<Entry>::void inorder(void (*visit)(Entry &));
//Post: The tree has been traversed in inorder sequence.
//Uses: The function recursive_inorder

template<class Entry>
void Binary_tree<Entry>::void postorder(void (*visit)(Entry &));
//Post: The tree has been traversed in postorder sequence.
//Uses: The function recursive_postorder

template<class Entry>
void Binary_tree<Entry>::void level_order(void (*visit) (Entry &));
//Post: The tree has been traversed in level order sequence.
//Uses: STL queue class

template<class Entry>
int Binary_tree<Entry>::int size() const;
//Post: Returns the number of nodes in the tree
//Uses: The function recursive_size

template<class Entry>
void Binary_tree<Entry>::void clear();
//Post: All nodes of tree have been deleted, root set to NULL
//Uses:  The function recursive_clear

template<class Entry>
int Binary_tree<Entry>::int height() const;
//Post: Returns the height of the tree,
 //where empty tree has height 0, one-node
 //tree has height 1, etc.
//Uses: The function recursive_height

template<class Entry>
void Binary_tree<Entry>::void insert(const Entry &);
//Pre:  Data of type Entry has been passed for insertion -
//note that the prototype need not include parameter names,
//only data types
//Post: Parameter has been inserted into the shortest
//subtree or into the left subtree if equal height
//Uses: The function recursive_insert

template<class Entry>
void Binary_tree<Entry>::Binary_tree (const Binary_tree<Entry> &original);
//copy constructor
//Post: creates a deep copy of tree original
//Uses:  The function recursive_copy

template<class Entry>
void Binary_tree<Entry>::Binary_tree & operator =(const Binary_tree<Entry> &original);
// overloaded assignment operator
//Post: The calling tree is reset as a deep copy of tree pointed to by original
//Uses:  The function recursive_copy



}   //destructor










  //Auxiliary function prototypes - MORE NEED TO BE ADDED
void recursive_preorder(Binary_node<Entry> *sub_root,
                       void (*visit)(Entry &));

void recursive_inorder(Binary_node<Entry> *sub_root,
                       void (*visit)(Entry &));

void recursive_postorder(Binary_node<Entry> *sub_root,
                       void (*visit)(Entry &));

Binary_node<Entry>* recursive_copy(Binary_node<Entry>* sub_root);
//Pre: sub_root is NULL or points to a subtree of the Binary_tree
//Post: returns a pointer to a deep copy of tree pointed to by sub_root

If your trying to pass a function pointer, use typedef and it'll simplify your code.

typedef void (*myfunc)();

void thefunc(myfunc p)
{
//...
}

Try this:

template<class Entry>
void Binary_tree<Entry>::preorder(void (*visit)(Entry &))

and leave out the middle void.

Try this:

template<class Entry>
void Binary_tree<Entry>::preorder(void (*visit)(Entry &))

and leave out the middle void.

That worked. thanks.

This article has been dead for over six months. Start a new discussion instead.