On 19 Apr, 2006, at 20:56, Daniel Pape wrote:
I'm simply trying to pass an iterator to a template function. Here is
a simplified example that still has the error I'm seeing. I get
(approximately) the same error with g++ 3.2.3, 3.3.6 and 3.4.5
---------------
#include <vector>
template <class T>
void one(typename std::vector<T>::iterator it)
{
(*it)++;
}
int main(int ac, char **av)
{
std::vector<int> v(10);
one(v.begin());
return 0;
}
---------------
g++ test.cpp
test.cpp: In function `int main(int, char**)':
test.cpp:12: error: no matching function for call to
`one(__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >)'
Hi,
your problem is that iterator is in a 'non-deducible context'. Look
for 'deducing template arguments' in the Stroustrup. If you cannot
use the obvious alternative
template <class I>
void one(I it)
{
(*it)++;
}
try looking into enable_if (this is in boost) and is_same (this is in
std::tr1) for a more or less direct way to do what you want.