2011-07-22 13 views
0

私はinitialyを作成した要素を値10で取り除きたいところで、次のコードを書いています。イテレータを設定して消去する際に問題があります。どうしたの?マルチレベルunordered_mapの要素を消去していますか?

#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 ===| 

答えて

3

あなたは1あまりにも多くの[0]を持っている:

さらに
_3d[0][0][0].begin(); 
// should be: 
_3d[0][0].begin(); 

map_itタイプ、ない変数です。タイプmap_itの変数を宣言し、その変数に代入または初期化する必要があります。

_3d[0][0].begin()のタイプは、単にboost::unordered_map<int, int>::iterator(またはconst_iterator)です。 _3d.begin()のタイプは、使用しようとしているネストされたイテレータータイプになります。

追加のtypedefをいくつか追加すると、このコードは非常に簡単になります。

関連する問題