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.
Change this declaration :
struct tree_node* minFunc( tree_node** node);
into this
tree_node* minFunc( tree_node** node);
Change it's definition accordingly.
- Double pointer is a sure sign of bad design
- 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
精彩评论