Am 20.11.2012 09:33, schrieb
:
>
> The following program does not compile using g++4.6.3, ¿why?
>
> #include <list>
>
> template <class T>
> void empty (typename std::list<T>::iterator it)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is a non-deducible context. Or, as Stephan T. Lavavej would say
"The double colon between T and 'iterator' prevents the compiler from
deducing T" (or something like that).
> {}
>
> int main()
> {
> std::list<int> l;
> empty(l.begin());
> }
Here, the compiler won't deduce the template parameter T as a general
rule. You can't expect the compiler to try every possible T and see what
fits. There are other cases where there is no "solution" for T:
template<class T>
struct foo {
typedef int blah;
}
template<class T>
void empty(typename foo<T>::blah);
int main()
{
empty(42); // What's T ?!
}
HTH,
SG