1

So i am initializing an iterator through a map like this:

std::map<K, V>::iterator it = m_map.find(begin);

And I am using a GCC(7.2.0) compiler that is giving me these errors:

1.prog.cc:187:9: error: need 'typename' before 'unit_test::std::map::iterator' because 'unit_test::std::map' is a dependent scope std::map::iterator it = m_map.find(begin); 2. prog.cc:187:34: error: expected ';' before 'it' std::map::iterator it = m_map.find(begin);

I didn't think that I was initializing it wrong, but i would appreciate if anyone can help and knows what I have to change.

JFMR
  • 23,265
  • 4
  • 52
  • 76
dmiranda
  • 9
  • 2

1 Answers1

1

Instead of having the iterator's type hard-coded, you can simply use the auto keyword:

auto it = m_map.find(begin);

This way, the type of it will be deduced from its initializer ( m_map.find(begin) in this case).

JFMR
  • 23,265
  • 4
  • 52
  • 76