0

I have the BST class same as in this thread

BST.hpp

template<class T> 
class BinarySearchTree
{
 private:
  struct tree_node
  {
    tree_node* left;
    tree_node* right;
    T data;

    tree_node( const T & thedata, tree_node * l = NULL, tree_node * r = NULL )
            : data( thedata ), left( l ), right( r ) { }
  };
tree_node* root;

public:
  //some functions
private:
  struct tree_node* minFunc( tree_node** node);
};

I was trying to return a pointer from the function as done in this thread.

the definition of minFunc is in the same BST.hpp file

template <class T>
struct tree_node* BST<T>::minFunc(tree_node** node)
{
tree_node* current = *node;
while(current->left != NULL)
{
    current = current->left;
}
return current;
}

Unable to figure out the compile errors:

error C2143: syntax error : missing ';' before '*'

error C2065: 'T' : undeclared identifier

error C2955: 'BST' : use of class template requires template argument list

error C2509: 'minFunc' : member function not declared in 'BST'

all these pointing to the definition

4
  • 1
    probably the missing ; screws everything up Commented May 29, 2011 at 10:33
  • Have you included the header file for BST in the .cpp? Commented May 29, 2011 at 10:36
  • @BlackBear There's no missing ;, the compiler is being misleading. Commented May 29, 2011 at 10:38
  • @Node, since its a templated class, all the code is in same .hpp file Commented May 29, 2011 at 13:31

3 Answers 3

2

My best guess is that struct tree_node is not visible. It's probably not declared / declared inside some class.

Sign up to request clarification or add additional context in comments.

1 Comment

its a private member of the class BST and the entire code is in .hpp file. Is it still a problem?
1
  1. Change this declaration :

    struct tree_node* minFunc( tree_node** node);

into this

tree_node* minFunc( tree_node** node);

Change it's definition accordingly.

  1. Double pointer is a sure sign of bad design
  2. Did you include a header defining struct tree_node?

EDIT

The definition should be

template <class T>
typename BST<T>::tree_node* BST<T>::minFunc(tree_node** node)
{
tree_node* current = *node;
while(current->left != NULL)
{
    current = current->left;
}
return current;
}

by the way, take a note that the method minFunc is private and cant access it outside of the class

4 Comments

removing struct gives C4430 on the definition. @2. I have put everything in same .hpp file.
@Kaushik Did you put the definition of tree_node before class BinarySearchTree?
definition of tree_node is put inside class BinarySearchTree. I have put the code in the thread.
correct. 1. I missed the typename in the function definition. 2. Regarding private member, my intention is similar to link this thread.
0

treenode is a private struct in BST - you cannot access it outside BST

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.