template-nested STL iterator question
I'm curious about what appears to be a restriction on using an STL
container inside a user-defined template, esp. using an iterator to
such a container. It's not clear to me if this is a general
template/language restriction, and STL iterator limitation, or if I'm
just going about it wrong.
I'm declaring a template which uses a std::map to store references to
the template type, e.g.
template template <typename T>
class MyClass
{
public:
// ...
private:
std::map<std::string, T*> m_objectMap;
};
This compiles fine. However if I have a declaration of an iterator to
this map in a method of my class, the compile fails, e.g.
template template <typename T>
class MyClass
{
public:
T* Lookup(std::string)
{
T* pT = NULL;
std::map<std::string, T*>::iterator iTptr = m_objectMap.find();
if(iTptr != m_objectMap.end())
pT = *iTptr;
return pT;
}
private:
std::map<std::string, T*> m_objectMap;
};
Is there a correct way to accomplish this? If not, anyone know the
rationale?
The kludgy workaround I'm using is to use void * instead of T* for the
std::map and static-cast it.
- Chris