c++ - 为什么我会收到“clang++:错误 - 没有匹配的函数调用”’”?
问题描述
我在 C++ 中有一个简单的函数,它检查给定元素是否存在于给定数组中并相应地返回true
或返回false
。这是代码示例以及我如何尝试使用它:
#include <iostream>
using namespace std;
bool find_elem(string array[], string elem)
{
return (find(begin(array), end(array), elem) != end(array));
}
int main(void)
{
string names[] = {"Bob", "Bill", "Sally", "Mark"}
if (find_elem(names, "Bob))
{
cout << "Bob is in the array" << endl;
}
else
{
cout << "Bob is not in the array" << endl;
}
return 0;
}
我在find_elem()
函数的返回语句上收到一条错误消息clang++: error - no matching function for call to 'begin'
,以及另外两个对end
. 我不确定为什么会发生这种情况,因为这行代码在main()
我的程序功能中运行良好,但如果我尝试在其他任何地方使用它,它会返回错误。有人可以解释为什么会发生这种情况以及我该如何解决吗?我最近才开始学习 C++,因此非常欢迎有关如何更好地做到这一点的示例或建议。
解决方案
推荐阅读
- django - Django + Angular = 全局变量
- php - 尝试有条件地实现 ElasticSearch 排序
- android - 如何构建指纹识别应用程序
- c# - 是否可以初始化属性更改值?
- python - 如何在保留空行的同时从 MD 文件中的每一行中删除前导和尾随空格?
- matlab - 从另一个向量中获取有序整数向量
- python - 在 Android Studio 上集成 Python 库 Spleeter
- c++ - 即使我将类型转换为 long int (C++),也会发生整数溢出
- mysql - 在 Laravel 8 中,每天早上 6:00 将客户端数据库同步到我自己的数据库项目
- c# - 无法计算表达式