C++ C++;向量:函数不可行+;没有匹配函数
所以,似乎每次我尝试编译时,都会遇到一个涉及 “错误:调用“搜索”和“报告”时没有匹配函数”C++ C++;向量:函数不可行+;没有匹配函数,c++,vector,C++,Vector,所以,似乎每次我尝试编译时,都会遇到一个涉及 “错误:调用“搜索”和“报告”时没有匹配函数” void search_和_报告(向量名称[],…) ... 载体名称(n); ... 搜索和报告(名称,…); 您已声明search\u和
void search_和_报告(向量名称[],…)
...
载体名称(n);
...
搜索和报告(名称,…);
您已声明search\u和
获取指向vector
s数组的指针,但您正在向其传递vector
。编译器找不到要调用的适当函数,因为您的类型不匹配。void search\u and\u report(向量名[],…)
...
载体名称(n);
...
搜索和报告(名称,…);
您已声明
search\u和
获取指向vector
s数组的指针,但您正在向其传递vector
。编译器找不到要调用的适当函数,因为您的类型不匹配。从您提供的链接中,函数搜索和报告的签名是:
void search_and_report(vector<const string> names[], int n, string name,
string label,
bool (*search)(vector<const string> names[], int n,
string name, int &count));
从您提供的链接中,函数搜索和报告的签名为:
void search_and_report(vector<const string> names[], int n, string name,
string label,
bool (*search)(vector<const string> names[], int n,
string name, int &count));
与此错误消息相关的信息包括(1)声明的函数名与调用中使用的函数名,(2)函数是否在此范围内声明,(3)实际参数类型与形式参数类型。在其他地方做什么,例如在其他地方初始化向量,并不重要。请务必在此处发布一个完整但最少的示例,代码在这里,而不是在场外。功能搜索和报告的签名是什么?@cheers-sandhth.-Alf,可以。对不起,介意我问一下为什么在网站外发布不是一件好事吗?@ichramm,我现在可以编辑并添加它了!您需要更改函数以获取与此错误消息相关的vector
(可能通过常量引用),而不是vector
,尤其是vector[]
,包括(1)声明的函数名与调用中使用的函数名,(2)函数是否在此范围内声明,(3)实际参数的类型与形式参数的类型。在其他地方做什么,例如在其他地方初始化向量,并不重要。请务必在此处发布一个完整但最少的示例,代码在这里,而不是在场外。功能搜索和报告的签名是什么?@cheers-sandhth.-Alf,可以。对不起,介意我问一下为什么在网站外发布不是一件好事吗?@ichramm,我现在可以编辑并添加它了!您需要更改函数以获取vector
(可能通过常量引用),而不是vector
,尤其是不是vector[]
明白了!谢谢现在我只需要修复我的二进制搜索,因为它找不到任何东西。可能是因为搜索不是二进制的!只需注意:二进制搜索仅在向量按顺序排列时有用:根据当前元素的值,将元素置于中间并向左或向右跳转。否则它只能用线性搜索。哦,是的,我明白你的意思。这里有一个排序函数。我想我应该检查一下,看看它是否和向量一起工作。我用一些伪代码更新了我的答案,希望能有所帮助!知道了!谢谢现在我只需要修复我的二进制搜索,因为它找不到任何东西。可能是因为搜索不是二进制的!只需注意:二进制搜索仅在向量按顺序排列时有用:根据当前元素的值,将元素置于中间并向左或向右跳转。否则它只能用线性搜索。哦,是的,我明白你的意思。这里有一个排序函数。我想我应该检查一下,看看它是否和向量一起工作。我用一些伪代码更新了我的答案,希望能有所帮助!
void search_and_report(std::vector<const string> names[], int n, string name, string label,
bool (*search)(vector<const string> names[], int n, string name,
int &count))
void search_and_report(vector<const string> names[], ...)
...
vector<string> names(n);
...
search_and_report(names,...);
void search_and_report(vector<const string> names[], int n, string name,
string label,
bool (*search)(vector<const string> names[], int n,
string name, int &count));
bool binary_search(vector, str, begin, end) {
int m = (end + begin) / 2;
if (vector[m] < str) {
return binary_search(begin, m-1);
}
if (vector[m] > str) {
return binary_search(m+1, end);
}
return true;
}