因此,我有一个函数,即预订处理,用于在bst的每个节点中的每个项目上执行函数f。功能如下:
template <class Item, class Key, class Process>
void preorder_processing(bstNode<Item, Key>*& root, Process f)
{
if (root == NULL) return;
f(root);
preorder_processing(root->left(), f);
preorder_processing(root->right(), f);
}
template<class Item>
void print(Item a)
{
cout << a << endl;
}
bstNode.cxx:23: error: no matching function for call to ‘
preorder_processing(bstNode<int, long unsigned int>* <unresolved overloaded function type>)
’
最佳答案
您的root->left()
和root->right()
应该返回的bstNode<Item, Key>*
是右值指针。您不能将非常量引用分配给临时指针变量。
如下更改声明,编译器错误应该出现:
void preorder_processing(bstNode<Item, Key>* root, Process f)
// removed reference ^^^
Process f
不会传递任何值:preorder_processing(root->left(), ???);
https://stackoverflow.com/questions/10442735/
相关文章:
iphone - 如何解决iPhone应用程序hpple HTML解析 'libxml/tree.h
visual-studio-2010 - VS2010 Express 中的 Boost - 重新定
testing - Flex Builder : Asset file or directory n
apache-flex - 类mx.core::DesignLayer could not be f
ruby - 为什么在编译ruby-1.9.3-p125时出现clang错误?