Hi, I am trying to write a function template which takes starting and end addresses for an array and the value to search. But when I call this function, I get linker error 1120 - 1 unresolved external.
Can you please check what am I doing wrong?
Can you please check what am I doing wrong?
Code:
template <typename T>
bool find(T* first, T* last, T& value)
{
bool result = false;
if ((first) && (last))
{
while (first != last)
{
if (*first == value)
{
result = true;
break;
}
first++;
}
}
return result;
}
int main()
{
int arr[] = {1,2,3,4,5};
vector<int> vect;
vect.push_back(arr[1]);
vect.push_back(arr[2]);
vect.push_back(arr[3]);
vect.push_back(arr[4]);
vect.push_back(arr[5]);
int val_to_check = 3;
bool result1 = find(arr, arr+4, val_to_check);
bool result2 = find(&vect[0], &vect[4], val_to_check);
cout << result1 << " " << result2 << endl;
return 0;
}
Comment