Page 1 of 1
how to iterate a C++ map of map
Posted: October 13th, 2011, 4:30 am
by JackBryan
I have a map of map std::map< int, std::map > myMap; std::map< int, std::map >::iterator itr;When I try to iterate it : itr = myMap.find(nodeI); // nodeI is int if (itr == myMap.end()) { exit(1) ; } I got error: error: no match for âoperator=â in âitr = ((const PushList*)this)->PushList::myMap.std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = int, _Tp = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> > >, _Compare = std::less<int>, _Alloc = std::allocator<std:air<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> > > > >](((const int&)((const int*)((int*)nodeI))))âHow can I iterate the map of map ?Any help is really appreciated .thanks
how to iterate a C++ map of map
Posted: October 13th, 2011, 7:06 am
by MattF
Don't you need to specify the datatypes of the inner map?
how to iterate a C++ map of map
Posted: October 13th, 2011, 7:32 am
by DevonFangs
QuoteOriginally posted by: MattFDon't you need to specify the datatypes of the inner map?Yes he does.Jack, pls use "attach code" button next time Also, there might be some overhead in using map of map. Are you sure you can't just use a single map with a little more complicated key instead?
how to iterate a C++ map of map
Posted: October 13th, 2011, 9:28 am
by nosbor
do you need to overload the operator < assuming your types are not the built in ones
how to iterate a C++ map of map
Posted: October 13th, 2011, 9:31 am
by DevonFangs
QuoteOriginally posted by: nosbordo you need to overload the operator < assuming your types are not the built in onesYou need the operator< to be defined for the key type. In this case it's just int, so it's not an issue.
how to iterate a C++ map of map
Posted: October 13th, 2011, 9:43 am
by nosbor
yeah but what are the types of the inner map ?
how to iterate a C++ map of map
Posted: October 13th, 2011, 9:51 am
by DevonFangs
QuoteOriginally posted by: nosboryeah but what are the types of the inner map ?MattF already pointed out that it's the problem. When we hear back from JackBryan we'll figure it out.
how to iterate a C++ map of map
Posted: October 13th, 2011, 2:52 pm
by Cuchulainn
Similar to this idea.
how to iterate a C++ map of map
Posted: October 13th, 2011, 6:26 pm
by Cuchulainn
how to iterate a C++ map of map
Posted: October 14th, 2011, 1:16 pm
by TradesMan
see this example: