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

Community
  • 1
  • 1
Kaushik Acharya
  • 1,520
  • 2
  • 16
  • 25

3 Answers3

2

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

cnicutar
  • 178,505
  • 25
  • 365
  • 392
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

BЈовић
  • 62,405
  • 41
  • 173
  • 273
  • removing struct gives C4430 on the definition. @2. I have put everything in same .hpp file. – Kaushik Acharya May 29 '11 at 13:39
  • @Kaushik Did you put the definition of tree_node before class BinarySearchTree? – BЈовић May 29 '11 at 15:00
  • definition of tree_node is put inside class BinarySearchTree. I have put the code in the thread. – Kaushik Acharya May 30 '11 at 01:40
  • correct. 1. I missed the **typename** in the function definition. 2. Regarding private member, my intention is similar to [link](http://stackoverflow.com/questions/5373905/why-does-this-search-function-return-a-pointer-to-a-pointer) this thread. – Kaushik Acharya May 30 '11 at 13:42
0

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

slashmais
  • 7,069
  • 9
  • 54
  • 80