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.insert(pair<int, A>(5, aobj));
// many insert statements here....
std::pair<multimap<int,A>::iterator,multimap<int,A >::iteratorret;
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. 1 2210 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.insert(pair<int, A>(5, aobj));
// many insert statements here....
std::pair<multimap<int,A>::iterator,multimap<int,A >::iteratorret;
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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;
|
by: DaKoadMunky |
last post by:
Please consider the following...
<CODE>
#include <string>
using namespace std;
typedef int PrimitiveType;
typedef string ClassType;
|
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...
|
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,
|
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...
|
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
|
by: howa |
last post by:
Hi,
Consider a simple example, e.g.
var a = {
'a': 'b',
'c': 'd'
}
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
| |