PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Multimap - retrieve when the value is not a primitive type
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Multimap - retrieve when the value is not a primitive type

Réponse
 
LinkBack Outils de la discussion
Vieux 03/06/2008, 13h50   #1
ambarish.mitra@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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, A> mechanics;
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 >::iterator> ret;

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 /pointers?

Regards.







  Réponse avec citation
Vieux 03/06/2008, 13h58   #2
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Multimap - retrieve when the value is not a primitive type

ambarish.mitra@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, A> mechanics;
> 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 >::iterator> ret;
>
> 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07979 seconds with 10 queries