0

I try to use boost unordered_map with key as template variable.

 template<typename T>
std::string CPerformanceWatcher<T>::CheckPerformance(T &sOrderID, bool bDeleteRecord)
{
        boost::unordered_map<T, int>::iterator iter;
        iter = m_OrderIDTimeValMap->find(sOrderID);
        if(iter == m_OrderIDTimeValMap->end())
        {
            return false;
        }
        return false;
}

But the compile complains with syntax error. So my question is if I cannot use such an iterator?

user1402725
  • 87
  • 2
  • 8
  • possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – jrok Oct 04 '13 at 07:23

1 Answers1

3

You need to resolve the dependent name using typename keyword:

typename boost::unordered_map<T, int>::iterator iter;

See for more info on dependent names:

http://en.cppreference.com/w/cpp/language/dependent_name

How do you understand dependent names in C++

Community
  • 1
  • 1
goji
  • 6,911
  • 3
  • 42
  • 59