开发者

compile error in pointer return

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开发者_StackOverflow社区' : 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


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


  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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜