I want to make a function that takes a container T (can be vector, map, list...) as template and a T and a Int as arguments, in this function, we're assuming that T is a container of int, and I want to return the first occurence of the int in the container. Here's the function:
template <class T> int & easyfind(T container, int n)
{
typename T<int>::iterator it;
for (it = container.begin(); it != container.end(); it++)
if (*it == n)
return (*it);
throw (NotFoundException());
}
But the compiler says "expected a qualified name after 'typename'", and when I replace the typename
by class
the compiler says "explicit specialization of non-template class 'T'", how can I get this to work?
T
is a container ofint
, so you don't have to specify that.T<int>::iterator
-->T::iterator
.()
afterthrow
are superfluous.