没有匹配的呼叫功能

时间:2011-10-17 15:16:10

标签: c++

我一直在收到此错误,我无法弄清楚如何修复它:

btree.tem:98:   instantiated from 'std::pair<typename btree<T>::iterator, bool> btree<T>::insert(const T&) [with T = char]'
test.cpp:13:   instantiated from here
btree.tem:37: error: no matching function for call to 'btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>*&)'
btree.h:178: note: candidates are: void btree<T>::addElem(std::_List_iterator<node<T>*>&, node<T>&) [with T = char]
btree.tem:98:   instantiated from 'std::pair<typename btree<T>::iterator, bool> btree<T>::insert(const T&) [with T = char]'
test.cpp:13:   instantiated from here
btree.tem:48: error: no matching function for call to 'btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>*&)'

在我的头文件中,我有这个setter函数:

void addElem (std::_List_iterator<node<T>*>& itr, node <T>& n) {
  neighbours.insert(itr, n); 
}

我不知道它有什么问题。每当我这样称呼时,错误似乎就会发生:

class list < node<T>* >::iterator itr = bt->level().begin();
node <T>*n = new node<T>(elem, bt->max());
bt->addElem(itr, n);

有什么问题?

3 个答案:

答案 0 :(得分:1)

编译器正在寻找:

btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>*&)

但它只找到了一些东西:

btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>&)

您正在传递指向您的函数的指针。你没有定义一个以指针作为最后一个参数的addElem

答案 1 :(得分:0)

n是一个指针,所以你必须写下这个:

bt->addElem(itr, *n);

从错误消息中可以清楚地看出:

 btree.tem:37: error: no matching function for call to 
'btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>*&)'   

 btree.h:178: note: candidates are: 
 void btree<T>::addElem(std::_List_iterator<node<T>*>&, node<T>&) [with T = char]

请参阅错误中的第二个参数类型以及建议的候选人。

答案 2 :(得分:0)

错误不是“从......实例化” - 这是描述哪些模板实例化导致错误的上下文。

错误是

btree.tem:37: error: no matching function for call to 
'btree<char>::addElem(std::_List_iterator<node<char>*>&, node<char>*&)'

列出候选人:

note: candidates are: 
void btree<T>::addElem(std::_List_iterator<node<T>*>&, node<T>&) 
[with T = char]

所以它期待node<char>,而不是指针node<char>*