我的二进制搜索树 c++ 的递归函数中的错误 C2784 无法推断模板参数
error C2784 in recursive functions of my BinarySearch Tree c++ could not deduce template argument
我的两个递归函数都收到以下错误。我自己似乎找不到问题所在。如果有人能帮我,我很感激。
错误3 错误 C2784:"void 插入(树节点 *&,项类型)":无法从"项目类型 *"推断出"树节点 *&"的模板参数
错误1 错误 C2784:"void Destroy(树节点 *&)":无法从"项目类型 *"推断出"树节点 *&"的模板参数
template <class ItemType>
void Destroy(TreeNode<ItemType>*& tree)
{
if (tree != NULL)
{
Destroy(tree->left);
Destroy(tree->right);
delete tree;
}
}
template <class ItemType>
void Insert(TreeNode<ItemType>*& tree, ItemType item)
{
if (tree == NULL)
{ // Insertion place found.
tree = new TreeNode<ItemType>;
tree->right = NULL;
tree->left = NULL;
tree->info = item;
}
else if (item < tree->info)
Insert(tree->left, item); // Insert in left subtree.
else
Insert(tree->right, item); // Insert in right subtree.
}
template<class ItemType>
struct TreeNode
{
ItemType info;
ItemType* left;
ItemType* right;
};
template<class ItemType>
void TreeType<ItemType>::InsertItem(ItemType item)
{
Insert(root, item);
}
template<class ItemType>
TreeType<ItemType>::~TreeType()
{
Destroy(root);
}
你忘了把
template <class ItemType>
在定义Insert
之前.您也忘记了Destroy
右大括号后的分号.当我修复这些错误时,在 GCC 4.9 下编译的东西。
插入/销毁都是帮助程序函数。错误仅在我使用这些函数时发生。
template<class ItemType>
void TreeType<ItemType>::InsertItem(ItemType item)
{
Insert(root, item);
}
template<class ItemType>
TreeType<ItemType>::~TreeType()
{
Destroy(root);
}
相关文章:
- C++声明模板参数阴影模板参数错误
- 为什么 CRTP 模板C++给出无效参数错误?
- (C/C++)fscanf_s从txt文件以字符形式读取数组时缺少整数参数错误
- 参数错误可能与类型不匹配有关?
- printf 和 strftime 的参数错误无效
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 如何修复"没有重载函数需要 2 个参数"错误C++
- 术语不计算为函数采用 1 个参数错误?
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 为什么我不能像使用 std::string::size_type 那样使用 QList::size_type?(模板参数错误)
- cudaFreeHost() 无效参数错误
- 精神语法不会编译:函数模板参数错误?
- C 功能具有参考参数错误的迭代器错误.寻求解释
- 使用getDefaultCommConfig使用无效的参数错误
- C++ 可变参数模板和模板模板参数:错误:模板参数列表中参数 1 处的类型/值不匹配
- 使用SWIG生成的Python库时,向量分配器参数错误
- 错误C2664:无法转换参数错误
- C 作为参数错误的功能
- 命令行参数错误
- 增强Python参数错误