Dilip <rd*****@lycos.comwrote:
Folks
I understand that the keyword typename is also used to indicate that a
dependant parameter is a type. However I am a little unsure why I
need typename in this following example:
template<typename K, typename V>
class MyMap
{
public:
typedef typename std::map<K, V>::iterator MyMap_Iterator;
};
why is a typename needed here? what does iterator have to do with the
template parameters K and V? Irrespective of what K and V are am I
not trying to just typedef std::map's iterator? What am I missing?
Afaik, 'iterator' _could_ (just suppose you have not seen the class
definition, yet) also be a function or a static member variable. By
prepending 'typename' you tell the compiler, that 'iterator' really is a
type inside this specialization of the template, so it does not have to
look it up itself.
I am sure there is a more technical and more accurate explanation to
this, like a quote from the Standard. The above is what I use to
determine, if I need 'typename' or not. I got this explanation from this
newsgroup as well, btw. Try googling the groups for my name and
'typename' in the subject.
hth
--
jb
(reply address in rot13, unscramble first)