How to change all the values in the map?

A

Allen

I want to reset all the values in the map, but the codes cannot run
correctly.

typedef std::map<void*, int*> v2pmap;
v2pmap m;
....
m[v1] = p1;
m[v2] = p2;
m[v3] = p3;
....
v2pmap::iterator itr = m.begin();
while (itr != m.end())
{
void* vptr = itr->first;
m[vptr] = NULL;
}

I use v2pmap in a embedded system project. m is initialized with known
keys which mapping values change. I donot want to clear m and insert
key value mapping entries again and again.
So how reset the values to be NULL?

Thank you.
Allen
 
A

Allen

Allen said:
I want to reset all the values in the map, but the codes cannot run
correctly.
typedef std::map<void*, int*> v2pmap;
v2pmap m;
...
m[v1] = p1;
m[v2] = p2;
m[v3] = p3;
...
v2pmap::iterator itr = m.begin();
while (itr != m.end())
{
  void* vptr = itr->first;
  m[vptr] = NULL;

You mean "itr->second=NULL;"
I use v2pmap in a embedded system project. m is initialized with known
keys which mapping values change. I donot want to clear m and insert
key value mapping entries again and again.
So how reset the values to be NULL?

Set "second".

 application_pgp-signature_part
< 1KViewDownload

Yes, it does work. So easy implementation method!
Thank you very much.

Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top