|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|