|
template <class ForwardIterator, class Type>
ForwardIterator find(ForwardIterator first, ForwardIterator last, Type value)
{
for (; first!=last; ++first)
if (value==*first)
return first;
return last;
}
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int search_value;
int ia[6] = {27, 210, 12, 47, 109, 83};
cout<<"enter search value: ";
cin>>search_value;
int *presult = find(&ia[0], &ia[6], search_value);
cout<<"The value "<<search_value<<(presult == ia+6 ? "is not present" : "is present")<<endl;
return 0;
}
=================================[root@localhost root]# g++ temp.cpp
temp.cpp: In function `int main()':
temp.cpp:19: error: call of overloaded `find(int*, int*, int&)' is ambiguous
temp.cpp:3: error: candidates are: ForwardIterator find(ForwardIterator,
ForwardIterator, Type) [with ForwardIterator = int*, Type = int]
/usr/include/c++/3.3.3/bits/stl_algo.h:293: error: _InputIter
std::find(_InputIter, _InputIter, const _Tp&) [with _InputIter = int*, _Tp = int] |
|