473,569 Members | 2,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multimap - retrieve when the value is not a primitive type

Hi all,

I have a multimap, where key is an int and the value is a class. I can
insert into the multimap, but finding it difficult to retrieve the
value when keys match. I can do this with primitive types (int/char
etc).

Example:

class A {
public:
int vol;
int temp;
};

multimap<int, Amechanics;
multimap<int, A>::iterator it;

A aobj;
aobj.vol=10;
aobj.temp=20;

mechanics.inser t(pair<int, A>(5, aobj));
// many insert statements here....
std::pair<multi map<int,A>::ite rator,multimap< int,A>::iterato rret;

ret = mechanics.equal _range(5);

for (it=ret.first; it!=ret.second; ++it)
// How to read the object that matches the key in the multimap?
;
Upto this is okay, but then how can I find out the object
corresponding to the given key in the multimap?

Any help/pointers?

Regards.



Jun 27 '08 #1
1 2220
am************@ gmail.com wrote:
Hi all,

I have a multimap, where key is an int and the value is a class. I can
insert into the multimap, but finding it difficult to retrieve the
value when keys match. I can do this with primitive types (int/char
etc).
Strange. There is no difference when it comes to class types.

Example:

class A {
public:
int vol;
int temp;
};

multimap<int, Amechanics;
multimap<int, A>::iterator it;

A aobj;
aobj.vol=10;
aobj.temp=20;

mechanics.inser t(pair<int, A>(5, aobj));
// many insert statements here....
std::pair<multi map<int,A>::ite rator,multimap< int,A>::iterato rret;

ret = mechanics.equal _range(5);

for (it=ret.first; it!=ret.second; ++it)
// How to read the object that matches the key in the multimap?
Did you try

it->second

;
[snip]
Best

Kai-Uwe Bux
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
13434
by: Tanguy Fautré | last post by:
Hello, does std::multimap make any guarantee about the insertion order? for example: int main() { std::multimap<int, int> Map;
8
3069
by: DaKoadMunky | last post by:
Please consider the following... <CODE> #include <string> using namespace std; typedef int PrimitiveType; typedef string ClassType;
9
7855
by: Dennis Jones | last post by:
Hi, Is there a way to iterate through a multimap in such a way as to encounter only the unique keys? In other words, since a multimap allows duplicate keys, I would like to iterate through the entire multimap, and if a particular key has duplicates, only see one of them. I don't think I care about which of the duplicate entries I see,...
3
6289
by: He Shiming | last post by:
Hi Folks, Happy holidays! I have a question regarding STL multimap. Basically, the current multimap<int,int> look like this: key=>value 1=>10, 1=>20, 1=>30,
4
4492
by: Nick Keighley | last post by:
Hi, I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators. consider this pseudo code:- int DataItem::genDerived () {
46
2477
by: clintonG | last post by:
Documentation tells me how but not when, why or where... <%= Clinton Gallagher http://msdn2.microsoft.com/en-us/library/saxz13w4(VS.80).aspx
5
8071
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
2182
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below)....
12
7431
by: brad | last post by:
Recently had a need to us a multimap container in C++. I now need to write equivalent Python code. How does Python handle this? k = 'Tom' k = 'Bob' k = 'Joe' .... Same key, but different values. No overwrites either.... They all must be inserted into the container
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.