Iterating over a reference to a map

Hello

I have a function returning a reference to a map, something like this:

1
2
3
4
5
6
7
8
9
const std::map<T1, T2>& get_some_map(void) const
{
  ...
}

void main(void)
{
  const std::map<T1, T2>& some_map = get_some_map();
}

Now I want to iterate over this map, so I declare
1
2
      std::map<T1, T2>::iterator it     = some_map.begin();
const std::map<T1, T2>::iterator it_end = some_map.end();

but I get an error when I compile. Where am I wrong? Thank you
Last edited on
1
2
3
4
const std::map<T1, T2>& some_map = get_some_map(); // const map

std::map<T1, T2>::const_iterator it     = some_map.begin(); // const_iterator
std::map<T1, T2>::const_iterator it_end = some_map.end();   // const_iterator 


C++11:
auto http://www.stroustrup.com/C++11FAQ.html#auto
range-based loop http://www.stroustrup.com/C++11FAQ.html#for
Topic archived. No new replies allowed.