I'm trying to iterator through a map object using the following chunk of code:
for(map<int, vector>::iterator table_iter = table.being(); table_iter != table.end(); table_iter++)
{
...
}
And I keep getting errors telling me:
conversion from const_iterator to non-scalar type iterator requested
And I can't seem to determine why the iterator would be const vs. not-const, or how to deal with this.
Use map<int, vector>::const_iterator instead which is returned by map::begin.
Sounds like table is a const object or reference, in which case begin returns a const_iterator. Change your for-loop to this:
// typedefs make for an easier live, note const_iterator
typedef map<int, vector>::const_iterator iter_type;
for(iter_type table_iter = table.begin(); table_iter != table.end(); table_iter++)
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With