reduced basic form, i'm trying binary search tree:
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); }
when call print_paths_bst, this: error: no matching function call ‘preorder_processing1(const bst<int, int>*&, <unresolved overloaded function type>, const bst<int, int>*&)’
i've tried forcing cast on preorder_processing1 call
preorder_processing1(root, print_if_leaf<item, key>, root);
...but hasn't resolved problem.
does see what's wrong this?
template <class item, class key, class process, class param> void preorder_processing1(bst<item, key> *root, process f, param g)
this needs take const bst<item, key> *
additionally, call f(root->val, g);
have problems - root->val
isn't bst<item, key> const *
. mean f(root, g)
Comments
Post a Comment