没有匹配的调用函数

No matching function for call

本文关键字:调用 函数      更新时间:2023-10-16

我一直得到这个错误,我不知道如何修复它:

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);

有什么问题吗?

编译器正在查找:

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

但是它只找到了:

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

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

错误不是" installed from…"-这是描述哪些模板实例化导致错误的上下文。

错误是

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>*

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]

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