I have the following code where I wanted to eliminate the element I created initialy with the value 10. I’m having trouble setting up an iterator and erasing it. How is it done?
#include <iostream>
#include <boost/unordered_map.hpp>
using namespace std;
int main()
{
typedef boost::unordered_map<int, boost::unordered_map<int, boost::unordered_map<int, int> > >::const map_it;
typedef boost::unordered_map<int, boost::unordered_map<int, boost::unordered_map<int, int> > > _map;
_map _3d;
_3d[0][0][0] = 10;
cout<<_3d[0][0][0]<<endl;
map_it = _3d[0][0][0].begin();
_3d[0][0][0].erase(map_it);
return 0;
}
multimapBoost.cpp||In function 'int main()':|
multimapBoost.cpp|16|error: expected unqualified-id before '=' token|
multimapBoost.cpp|18|error: request for member 'erase' in '((boost::unordered_map<int, int, boost::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, int> > >*)((boost::unordered_map<int, boost::unordered_map<int, int, boost::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, int> > >, boost::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, boost::unordered_map<int, int, boost::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, int> > > > > >*)_3d.boost::unorder|
multimapBoost.cpp|18|error: expected primary-expression before ')' token|
||=== Build finished: 3 errors, 0 warnings ===|
You have one too many
[0]:Further,
map_itis a type, not a variable; you need to declare a variable of typemap_itand assign to or initialize that variable.The type of
_3d[0][0].begin()is simplyboost::unordered_map<int, int>::iterator(orconst_iterator); the type of_3d.begin()would be the nested iterator type that you seem to be trying to use.A few additional typedefs would make this code very much straightforwarder.