#include<iostream>
#include<vector>
usingnamespace std;
template < class T, typename Y >
typename T::iterator find( typename T::iterator beg , typename T::iterator end , Y val )
{
while( *beg != val && beg ++ != end );
return beg;
}
int main()
{
vector<int> ivec;
int num;
cout << "Please enter some integers : " << endl;
while( cin >> num ) ivec.push_back( num);
cin.clear();
cout << "Please enter an integer you want to look for : " << endl;
cin >> num;
vector<int>::iterator it = ivec.begin();
if( ( it = find( it , ivec.end() , num ) ) != ivec.end() )
cout << "Find : " << *it << endl;
else cout << "Cannot finf it !" << endl;
return 0;
}
It compiles and works fine!
But, if i replace the function name "find" with some other names , it cannot get through the compiling... The compiler will say : "no matching function for call to ... " , OMG, i am really surprised, what's wrong?
I tried plenty of times, the symptom remains. I need your help.
As mentioned I think the compiler is using std::find because you have a "using namespace std" at the top of your code. So I suspect your template function never gets instantiated until you change its name. Then its errors show up when the compiler tries to deal with it.