I am trying to find an item in a range so I have multiple tests for my templated function called "find".
template <typename T> T* find(T *left, T *end, T item);
that is the function prototype I am using that fails to work with my first test which is:
static void TestFind1(void)
{
cout << "***** Find1 *****" << endl;
const int i1[] = {-1, 2, 6, -1, 9, 5, 7, -1, -1, 8, -1};
int size = sizeof(i1) / sizeof(int);
const int *end = i1 + size;
CS170::display(i1, end);
const int item = 9;
const int *pos = CS170::find(i1, end, item);
if (pos != end)
cout << "Item " << item << " is " << *pos << endl;
else
cout << "Item " << item << " was not found" << endl;
}
It says @ const int *pos "Error: no instance of function template "find" matches the argument list argument types are (const int [11], const int *, const int)"
I have a second prototype that works with this test but its not fully templated so It fails the second test which asks for a int *pos not a const int *pos.
second prototype:
template <typename T> const int* find(T *left, T *end, const int item);
I'm not quite sure how I'm supposed to template the first function to work with any case.