I'm working on a project for one of my classes and am running into a problem I've faced before but can no longer solve due to the use of templates.
The issue is with writing headers for functions that are being implemented outside of the class definition and have a return data type of a pointer to a private data member belonging to the class. Perhaps code will be the best explination:
// Print the contents to open stream out via a level order tranversal
void printTreeLevel(ostream &out) const;
// Returs the width, i.e, number of nodes in the largest level, of the tree
int width () const;
// Perform an LL rotation at the node containing x, if x is present and the
// rotation is possible.
// Return true on success, and false otherwise.
bool LLat (const ItemType &x);
// Perform a RR rotation at the node
// containing x, if x is present and the rotation is possible.
// Return true on success, and false otherwise.
bool RRat (const ItemType &x);
// Look up x in the Bst. If x is found, then anappropriate rotation (either LL or RR)
// is done at each node, starting from the parent px of x, along the path from px to
// root of the tree so that the result is a BST in which x is the root. Returns
// true if x is found, and false otherwise.
bool lookup (const ItemType& x);
};
Now directly below this code in the same Header file if I try to write this:
template <class ItemType>
BinarySearchTree<ItemType>::BinaryNode* BinarySearchTree<ItemType>::findMin() const
{
return privFindMin(root);
}// end findMind
The compiler throws and error saying "error C2143: syntax error: missing ';' before '*'.
Now I've had this error before in a simlar program where I wasn't using a templated class. To solve the error I did something like this....BinarySearchTree::BinaryNode * BinarySearchTree::privFindMin()
I did this because for some reason the compiler didn't seem to recognize the BinaryNode data type. However, with the addition of the extra BinarySearchTree:: it worked. But this fix is failing now because I have the <ItemType> and I guess its causing some other problems I don't know about. Anyone have any suggestions or insights into why this problem occurs. I know I could simply declare everything inside the class but I hate doing that and want to know the root of the problem.
Sorry this is my first forum post... Anyhow I tried what you said and it didn't work just said something about BinaryNode not being a type or something.