473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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
1 2037
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

14
by: Neil Zanella | last post by:
Hello, I would like to ask how come the design of C++ includes std::pair. First of all I don't think many programmers would use it. For starters, what the first and second members are depends...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
3
by: JustSomeGuy | last post by:
in the stl map class I see the use of a function pair and make_pair. What is the difference between pair and make_pair? dictionary.insert(std::pair<Key, Value>(k,v)); works as well as: ...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
14
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
11
by: kietzi | last post by:
Hello world, I was wondering whether it would be possible to create a map which uses a pair of ints as key and a float as value. I have used maps with const char* as key, but have so far not been...
1
by: flopbucket | last post by:
Hi, For the learning experience, I am building a replacement for std::map. I built a templated red-black tree, etc., and all the basic stuff is working well. I implemented basic iterators and...
4
by: Dean Card | last post by:
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the...
1
by: Saile | last post by:
I want to give an array the values from the specific multimap's key's values. multimap<string,int> mymultimap; multimap<string,int>::iterator it;...
4
by: qlin88 | last post by:
Hi, In STL multi-map, the lower_bound, upper_bound,equal_range all return an iterator. Now ifone wants to iterate from an upper bound towards a lower bound, what would be the best way to do it?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.