I’m trying to do this:
typedef std::map<std::string, time_t> my_map;
const mymap& some_function();
class bla
{
private:
my_map::iterator current
bla(const mymap& m) : current(m.begin())
{ }
}
And it’s not working. The somewhat more convoluted real error message is:
error: no matching function for call to ‘std::_Rb_tree_iterator, long int> >::_Rb_tree_iterator(std::map, long int>::const_iterator)’
I tried moving the initialization/assignment to the constructor body:
{ current = m.begin(); }
Which didn’t work either. So I thought, the type of current is wrong, so I just let the compiler deduce that:
...
decltype(my_map::begin()) current;
...
Which doesn’t work either.
All I need is an iterator member that is set at bla construction time, so I don’t have to explicitly set it in some stupid extra function and can iterate over the map externally through:
bool bla::do_stuff(...output...)
{
if(current = m.end())
return false;
balblabla(current);
++current;
return true;
}
You’re trying to assign
const_iteratortoiterator. There are two solutions:bla(my_map& m) : current(m.begin()) {}).const_iterator.