Re: typename keyword
cpluslearn@gmail.com ha scritto:
I have a basic question about the keyword 'typename'. typename has to
be used whenever a name that depends on a template parameter is a
type. But in the function foo() below I am using
vector<int>::const_iterator without typename. How does this work? How
does the compiler know that const_iterator is not a static member?
////////////////////////////////////////////////////////////////
using std::vector;
template <typename T>
void foo(T const& cont, vector<int> vec)
{
typename T::const_iterator tIter = cont.begin(); //This is OK
vector<int>::const_iterator vecIter = vec.begin(); //How does this
work without typename
typename vector<int>::const_iterator vecTypIter = vec.begin(); //do I
really need typename in this case.
}
It works because vector<int>::const_iterator does *not* depend on a
template parameter. In this context, the only template parameter is T
and there's no T in vector<int>::const_iterator.
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]