Приведенный к базовой форме, я пытаюсь сделать что-то подобное с бинарным деревом поиска:
template <class Item, class Key>
class bst
{
public:
Item val;
Key key;
bst *left;
bst *right;
private:
};
template <class Item, class Key, class Process, class Param>
void preorder_processing1(bst<Item, Key> *root, Process f, Param g)
{
if (root == NULL) return;
f(root->val, g);
preorder_processing1(root->left, f, g);
preorder_processing1(root->right, f, g);
}
template <class Item, class Key>
void print_path(const bst<Item, Key>* root, const Key target)
{
if (root->key != target)
{
cout << root->key << " " << root->val << endl;
if (target < root->key)
print_path(root->right, target);
else
print_path(root->left, target);
}
else
cout << root->key << " " << root->val << endl;
}
template <class Item, class Key>
void print_if_leaf(const bst<Item, Key>* test_node, const bst<Item, Key>* root)
{
if (test_node->right == NULL && test_node->left == NULL)
{
print_path(root, test_node->key);
cout << endl;
}
}
template <class Item, class Key>
void print_paths_bst(const bst<Item, Key>* root)
{
preorder_processing1(root, print_if_leaf, root);
}
Когда я вызываю print_paths_bst, я получаю это: error: no matching function for call to ‘preorder_processing1(const bst<int, int>*&, <unresolved overloaded function type>, const bst<int, int>*&)’
Я пытался вызвать приведение к вызову preorder_processing1, например
preorder_processing1(root, print_if_leaf<Item, Key>, root);
... но это также не решило проблему.
Кто-нибудь видит, что с этим не так?