【发布时间】:2014-12-04 03:34:19
【问题描述】:
我开发了一个双参数二叉搜索树,现在正尝试将它应用到创建字典。我在树中的 find 函数正常工作,但是,当我尝试在我的字典类中调用它时,我得到一个编译器错误“预期在 '>' 标记之前的主表达式”。谁能帮我理解出了什么问题?我对尝试从其他文件调用函数不是很熟悉。
这是我从 bst.h 内部的二叉搜索树中找到的函数
V & find (K key)
{
TreeNode<K,V> *traverseFind;
traverseFind = root;
unsigned int compareTraverseToHeight = 0;
while (compareTraverseToHeight < heightCount)
{
if (traverseFind == NULL) // Fallen off
{
keyFinder = 0;
break;
}
else if ( key == traverseFind->key )// Found key
{
keyFinder = 1;
break;
}
else if ( key < traverseFind->key )
{ .
traverseFind = traverseFind->left;
}
else
{
traverseFind = traverseFind->right;
}
compareTraverseToHeight++;
} // end of loop
if(keyFinder ==0)
{
throw key_not_found_exception();
}
cout<<"RETURNED "<<traverseFind->value<<endl;
return traverseFind->value;
}
还有字典:
#include bst.h
template <class K, class V> class Dictionary
{
public:
BinarySearchTree<K,V> wiktionary;
Dictionary()
{
}
~Dictionary()
{
}
V & find (K key)
{
return(wiktionary.find(<V>)); //this is the issue
}
private:
};
#endif
以及 main 中的应用程序:
int main()
{
Dictionary<string, int> d;
int val = d.find("abc");
if (val != 15)
throw dictionary_tester_exception(__FILE__, __LINE__);
return 0;
}
【问题讨论】:
-
使用
wiktionary.find(key):/ -
哦,哇,不知道我怎么没听懂。将此作为答案,我会接受,谢谢。
标签: c++ binary-search-tree header-files