没有匹配的调用函数
No matching function for call
我一直得到这个错误,我不知道如何修复它:
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]
请参阅错误中的第二个参数类型,以及建议的候选参数。
相关文章:
- 如何用参数值调用函数(仅在运行时已知)
- 从python中调用C++函数并获取返回值
- 当使用通配符和null指针调用函数时,对输出的说明
- 从R调用C++函数并对其进行集成时出错
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 如何在qt中从另一个类调用函数
- 在 COUT 语句中使用 COUT 调用函数
- 如何从线程中的不同模块调用函数?
- C++从函数指针数组调用函数
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 如何在 C/C++ 中从外部库调用函数
- 如何使用运算符在同一行中多次调用函数
- 是否可以创建一个从不同类调用函数的线程?
- 无法为类成员调用函数
- 如何从另一个标头 c++ 调用函数
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 如何只允许在调用函数 B 后调用函数 A?
- 我可以这样调用函数吗?
- 如何在 c++ 的类中递归调用函数方法?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?