Why doesn't C++ find template function? -
why compile error no matching function call `f( __gnu_cxx::__normal_iterator > >)'
?
#include <vector> template<typename t> void f(const typename std::vector<t>::iterator &) {} void g() { std::vector<int> v; f<int>(v.end()); // compiles. f(v.end()); // doesn't compile, gcc 4.3 can't find match. }
ultimately want write function takes vector iterator, , fails compile (with meaningful error) else. template<typename t>void f(const t&) {}
not solution, because compiles other types well.
g++ 4.8 gives more complete message: http://ideone.com/ekn3xs
note: template argument deduction/substitution failed: note: couldn't deduce template parameter ‘t’
f
doesn't directly takes t
(like in "const t&
") or type t
clear (like in "const std::vector<t>&
") nested dependent type (here std::vector<t>::iterator
) template type t
cannot automatically deduced argument.
edit: dietmar kühl's answer gives rationale example.
for "ultimately" part, check how check whether type std::vector::iterator @ compile time? (the accepted answer uses c++11 types, can use c++03 equivalents, e.g. boost)