似乎编译器非常接近于做我想做的事(因为它把我的函数称为候选函数),但我不知道我做错了什么。
#include <stdio.h>
#include <stdlib.h>
#include <list>
using namespace std;
template <class U, template<class U> class T>
void AppendSorted( T<U>& l, U val )
{
typename T<U>::reverse_iterator rt = l.rbegin();
while( ((*rt) > val) && (rt != l.rend()) )
rt++;
l.insert( rt.base(), val );
}
int main( int argc, char* argv[] )
{
list<int> foo;
AppendSorted<int, list<int> >( foo, 5 );
list<int>::iterator i;
for( i = foo.begin(); i != foo.end(); i++ )
{
printf("%d\n",*i);
}
return 0;
}
我得到的错误是:
test.cpp: In function ‘int main(int, char**)’:
test.cpp:21:43: error: no matching function for call to ‘AppendSorted(std::list<int>&, int)’
test.cpp:21:43: note: candidate is:
test.cpp:8:6: note: template<class U, template<class U> class T> void AppendSorted(T<U>&, U)