c++: How to transform a map iterator which point to pair into a “regular” pair pointe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danalovesc
    New Member
    • Sep 2010
    • 9

    c++: How to transform a map iterator which point to pair into a “regular” pair pointe

    those are the maps:

    Code:
     multimap<SortKey,T> firstMap;
        multimap<SearchKey,pair<SortKey,T>*> secondMap;
    
    
        template <class T,class SortKey, class SearchKey> bool GarageDataBase<T,SortKey,SearchKey>::Add(T data,SortKey key1, SearchKey key2) 
        {
         multimap<SortKey,T>::iterator it;
         it=(firstMap.insert(pair<SortKey,T>(key1,data)));
         pair<SortKey,T> *mizi=&*it;
         
         secondMap.insert(pair<SearchKey,pair<SortKey,T>*>(key2,mizi));
         return true;
        }

    I am trying to insert a pair into the firstMap and get a pointer to this pair and insert it into the "second" field in the secondMap

    so that i could go into my firstMap from the secondmap.

    Code:
    pair<SortKey,T> *mizi=&*it;
    this doesn't compile saying :

    error C2440: 'initializing' : cannot convert from 'std::pair<_Ty1 ,_Ty2> *' to 'std::pair<_Ty1 ,_Ty2> *'


    any idea whats going on or maybe a better way to make it work?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    As I see it your wamt to have an iterator from firstMap be the data for the pair in seciond Map.

    So this would be your secondMap:

    Code:
    multimap<SortKey,multimap<SortKey,int>::iterator > secondMap;

    Then you get an iterator from firstMap:

    Code:
         multimap<SortKey,T>::iterator it; 
         it= firstMap.find(key1,data)
    and insert it as the data value in secondMap:

    Code:
    	pair<SortKey,multimap<SortKey,int>::iterator > mizi;
    	mizi.first = key2;
    	mizi.second = it;
         secondMap.insert(mizi);
    Of course, I may be misunderstandin g your purpose. If so, please excuse me and I'll try again.

    Comment

    Working...