嘿,我对c ++比较陌生,想知道是否有人会告诉我为什么不能编译。我得到错误,如“没有匹配函数调用'搜索(int [10],int)'”和“模板参数推断/替换失败”该程序应该在int数组中搜索数字5,char数组为'm'和“nuts”的字符串数组
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
template<class T>
void search(T& a, T& b)
{
T temp = a;
T temp2= b;
int index=0;
bool found = false;
while((!found))
{
if(temp2==temp[index])
{
found = true;
}
else
{
index++;
}
}
if(found)
{
cout << temp[index]
<< "is located at index: " << index << endl;
}
}
int main()
{
int intarray[10]={3,5,9,14,15,19,21,34,47,52};
char chararray[10]={'b','d','e','g','i','k','m','o','r','t'};
string stringarray[10]={"all","big","cats","eat","food","grapes","hats","kelp","nuts", "rats"};
search(intarray, 5);
search(chararray, 'm');
search(stringarray, "nuts");
}