#include <vector>
#include <iostream>
using namespace std;
static const int NOT_FOUND = -1;
template <class sequence, class T>
int binarySearch(sequence& seq, int low, int high, T& item)
{
//..
}
template <class sequence, class T>
int binarySearch(const sequence& seq, const T& item)
{
if (seq.size() == 0)
return NOT_FOUND;
return binarySearch(seq, 0, seq.size() - 1, item);
}
int main()
{
vector<int> t1 = {0, 3 ,45, 94};
cout << binarySearch(t1, 0);
//binarySearch(t1, 0, t1.size() - 1, 45);
return 0;
}
Why does the compiler not accept:
template <class sequence, class T>
int binarySearch(sequence& seq, T& item)
?
Furthermore, why does the program as stated compile, but calling
binarySearch(t1, 0, t1.size() - 1, 45);
from main not compile?
The compiler error in any case is "No matching function for call to 'binarySearch'.