C++ Reference Guide mistake?

G

gob00st

I found the following paragraphs from C++ pro Danny Kalev's C++
Reference Guide at
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=206

stating:
_______________________________________________________________________________________________________________________________________
Let's look at a concrete example of a map that contains a pair of
strings, the first of which is a name and the second one is an e-mail
address. We create the map like this:

#include <map>
#include <string>

map <string, string> emails;
To add an item to a map, use the subscript operator:

emails["J. Horvath"]="(e-mail address removed)"; //#1
If the map already contains the key "J. Horvath", the current
associated value remains unchanged:

emails ["J. Horvath"]="(e-mail address removed)"; //#2 ,has no effect

_______________________________________________________________________________________________________________________________________

IMHO, this seems wrong. #2 should update the data_value of key "J.
Horvath" to "(e-mail address removed)".

Because I think essentially mymap[k] equals to (*(mymap.insert
(value_type(k, data_type())).first)).second ,which enables #2 to
update the value of key "J. Horvath".

I can not find any contact email of Danny, so I posted this issue
here, I am hoping someone could either confirm I am correct or
opposite.

Any input is appreciated.
Regards,
Gob00st
 
J

joecook

emails["J. Horvath"]="(e-mail address removed)"; //#1
If the map already contains the key "J. Horvath", the current
associated value remains unchanged:

emails ["J. Horvath"]="(e-mail address removed)"; //#2 ,has no effect>
IMHO, this seems wrong. #2 should update the data_value of key "J.
Horvath" to "(e-mail address removed)".

Because I think essentially mymap[k] equals to (*(mymap.insert
(value_type(k, data_type())).first)).second ,which enables #2 to
update the value of key "J. Horvath".

You are correct of course. Yikes. That is a rather glaring
misunderstanding of how std::map works (especially for someone writing
articles on the subject!). Something I might dismiss if it was 1994,
but 2004?

Joe C
 
G

gob00st

emails["J. Horvath"]="(e-mail address removed)"; //#1
If the map already contains the key "J. Horvath", the current
associated value remains unchanged:
emails ["J. Horvath"]="(e-mail address removed)"; //#2 ,has no effect>
IMHO, this seems wrong. #2 should update the data_value of key "J.
Horvath" to "(e-mail address removed)".
Because I think essentially mymap[k] equals to (*(mymap.insert
(value_type(k, data_type())).first)).second ,which enables #2 to
update the value of key "J. Horvath".

You are correct of course.   Yikes.  That is a rather glaring
misunderstanding of how std::map works (especially for someone writing
articles on the subject!).   Something I might dismiss if it was 1994,
but 2004?

Joe C

Thanks for the quick reply. I thought I was probably right, its just
Danny is a C++ expert, so I can't be 100% sure.
Looking at his profile, he was once a member of the C++ standards
committee between 1997 and 2000...
Anyway, I am sure I am correct now.
Gob00st
 
P

peter koch

I found the following paragraphs from C++ pro Danny Kalev's C++
Reference Guide athttp://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=206

stating: [snipped rubbish]
Because I think essentially mymap[k] equals to (*(mymap.insert
(value_type(k, data_type())).first)).second ,which enables #2 to
update the value of key "J. Horvath".

You are correct, of course. Sadly Danny Kalev is not the expert on C++
he claims to be - and he never was. The next time you (and others) see
his name, realise that is he talks about C++ you better not read it.

/Peter
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top