error: cannot convert in arguement passing
I have some code like this:
template <class Item,class Key>
class bst
{
public:
//bst(const Item& new_item,const Key& new_key);
Key get_key() const {return key;};
Item get_item() const {return item;};
bst get_right() const {return *rightPtr;};
bst get_left() const {return *leftPtr;};
void set_key(const Key& new_key) {key = new_key;};
void set_item(const Item& new_item) {item = new_item;};
void set_right(bst *new_right) {rightPtr=new_right;};
void set_left(bst *new_left) {leftPtr=new_left;};
Item item;
Key key;
bst *rightPtr;
bst *leftPtr;
private:
};
template <class Item,class Key,class Process,class Param>
void inorder_processing_param开发者_如何学Python(bst<Item,Key> *root,Process f,Param p)
{
if(root==NULL)
{return;}
else
{
inorder_processing(root->leftPtr,f,p);
f(root->item,p);
inorder_processing(root->rightPtr,f,p);
}
}
void perfect(studentRecord s)
{
if (s.GPA==4.0)
{
cout << s.id << " " << s.student_name;
}
}
void major_m(bst<studentRecord,int>* root)
{
if (root->item.major=="m")
{
cout << root->item.id << " " << root->item.student_name;
}
}
void print_major(bst<studentRecord,int>* root,char* m)
{
inorder_processing(root,major_m);
}
it make this error when i run it:
bst.template: In function `void inorder_processing(bst<Item, Key>*, Process)
[with Item = studentRecord, Key = int, Process = void (*)(bst<studentRecord,
int>*)]':
studentDatabase.cxx:97: instantiated from here
bst.template:151: error: cannot convert `studentRecord' to `bst<studentRecord,
int>*' in argument passing
how do i fix it
Change:
f(root->item,p);
To:
f(root);
Alternatively, add another param to major_m
and call it as f(root, p)
EDIT: Apparently you've not posted your
template <class Item,class Key,class Process,class Param>
void inorder_processing(bst<Item,Key> *root,Process f)
function. Given the code you have, I'll make a guess that you call f(root->item)
in it - when you need to do f(root)
精彩评论