template <typename Key,typename Value>
void add(SBTNode<Key,Value>*& t, const SBTNode<Key,Value>* x)
{
if (t==SBTNode<Key,Value>::getPNIL()) { t = x; return;}
if (x->key<t->key) add(t->left,x);
else if (t->key<x->key) add(t->right,x);
else { t->value+=x->value; return; }
maintain(t, t->key<x->key);
}
template <typename Key,typename Value>
class SBTree
{
private:
SBTNode<Key,Value>* root;
public:
SBTree():root(SBTNode<Key,Value>::getPNIL()) {}
void add(Key& key,Value& value) { add(root,new SBTNode<Key,Value>(key,value));}
};
Here,void add(Key& key,Value& value) { add(root,new SBTNode<Key,Value>(key,value));} };
, I want to call the first add function, however, the compiler seems to think that the only candidate function is the void add(Key& key,Value& value)
.
error: no matching function for call to 'SBTree<row_col, int>::add(SBTNode<row_col, int>*&, SBTNode<row_col, int>*)'
void add(Key& key,Value& value) { add(root,new SBTNode<Key,Value>(key,value));}
^~~
note: candidate: 'void SBTree<Key, Value>::add(Key&, Value&) [with Key = row_col; Value = int]'
void add(Key& key,Value& value) { add(root,new SBTNode<Key,Value>(key,value));}
I tried to replace to add<Key,Value>(root,new SBTNode<Key,Value>(key,value));
,the compiler just tell me <,> is wrong.
error: expected primary-expression before ',' token
void add(Key& key,Value& value) { add<Key,Value>(root,new SBTNode<Key,Value>(key,value));}
^
error: expected primary-expression before '>' token
void add(Key& key,Value& value) { add<Key,Value>(root,new SBTNode<Key,Value>(key,value));}
When I give the two functions different names, all is right, what's wrong with the function overloading in this case?