can anyone tell me why when i call the binary search function in int main() it tells me it cant match it to the template i have set up?
Code:
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
T binary_search(vector<T> data, T begin, T end, T searched_value)
{
if(begin > end)
return -1;
T mid = (begin + end)/2;
if (data[mid] == searched_value)
return mid;
else if (data[mid] < searched_value)
return binary_search(data, mid + 1, end, searched_value);
else
return binary_search(data, begin, mid - 1, searched_value);
}
int main()
{
vector<int> v;
cout << "Enter a series of integers: " << "\n";
int numbers;
while(cin >> numbers)
{
v.push_back(numbers);
}
cout << "\n";
cout << "What integer shall i search for?" << "\n";
int n;
cin >> n;
int pos = binary_search(v, 0, v.size()-1, n);
cout << "Found in position" << pos << "\n";
return 0;
}