I'm trying to return an iterator to a map from it's wrapper class. Finally got it to compile but wanted to ask why this didn't work.
To get this to compile I had to add typename to the front of the function prototype and definition.Code:template <typename key, typename value> class MgrBase { typedef typename std::map< key, value> MgrMap; typedef typename MgrMap::iterator MapIter; public: MgrBase(); virtual ~MgrBase(); MapIter Get(key ID); size_t getMemSize(); }; template <typename key,typename value> MgrBase<key,value>::MapIter MgrBase<key,value>::Get(key ID) { MgrMap::iterator map_iter(m_Objects.find(ID)); return map_iter; }
Why wasn't this enough?Code:template<typename key,typename value> class MgrBase { ... typename MapIter Get(key ID); ... }; template <typename key,typename value> typename MgrBase<key,value>::MapIter MgrBase<key,value>::Get(key ID) { MgrMap::iterator map_iter(m_Objects.find(ID)); return map_iter; }
Seems to me the typename is in the typedef so why did I have to add typename to the declaration and definition?Code:typedef typename MgrMap::iterator MapIter;


CornedBee