By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

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

P: 9
those are the maps:

Expand|Select|Wrap|Line Numbers
  1.  multimap<SortKey,T> firstMap;
  2.     multimap<SearchKey,pair<SortKey,T>*> secondMap;
  3.  
  4.  
  5.     template <class T,class SortKey, class SearchKey> bool GarageDataBase<T,SortKey,SearchKey>::Add(T data,SortKey key1, SearchKey key2) 
  6.     {
  7.      multimap<SortKey,T>::iterator it;
  8.      it=(firstMap.insert(pair<SortKey,T>(key1,data)));
  9.      pair<SortKey,T> *mizi=&*it;
  10.  
  11.      secondMap.insert(pair<SearchKey,pair<SortKey,T>*>(key2,mizi));
  12.      return true;
  13.     }
  14.  

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.

Expand|Select|Wrap|Line Numbers
  1. 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?
Sep 19 '10 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
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:

Expand|Select|Wrap|Line Numbers
  1. multimap<SortKey,multimap<SortKey,int>::iterator > secondMap;

Then you get an iterator from firstMap:

Expand|Select|Wrap|Line Numbers
  1.      multimap<SortKey,T>::iterator it; 
  2.      it= firstMap.find(key1,data) 
and insert it as the data value in secondMap:

Expand|Select|Wrap|Line Numbers
  1.     pair<SortKey,multimap<SortKey,int>::iterator > mizi;
  2.     mizi.first = key2;
  3.     mizi.second = it;
  4.      secondMap.insert(mizi); 
Of course, I may be misunderstanding your purpose. If so, please excuse me and I'll try again.
Sep 19 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.