Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ Reference Guide mistake?

Reply
Thread Tools

C++ Reference Guide mistake?

 
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-04-2009
I found the following paragraphs from C++ pro Danny Kalev's C++
Reference Guide at
http://www.informit.com/guides/conte...lus&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"]=""; //#1
If the map already contains the key "J. Horvath", the current
associated value remains unchanged:

emails ["J. Horvath"]=""; //#2 ,has no effect

__________________________________________________ __________________________________________________ ___________________________________

IMHO, this seems wrong. #2 should update the data_value of key "J.
Horvath" to "".

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

 
Reply With Quote
 
 
 
 
joecook@gmail.com
Guest
Posts: n/a
 
      02-04-2009
On Feb 4, 10:36*am, gob0...@googlemail.com wrote:
> emails["J. Horvath"]="jhorv...@mail.com"; //#1
> If the map already contains the key "J. Horvath", the current
> associated value remains unchanged:
>
> emails ["J. Horvath"]="newa...@com.net"; //#2 ,has no effect>
> IMHO, this seems wrong. #2 should update the data_value of key "J.
> Horvath" to "newa...@com.net".
>
> 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
 
Reply With Quote
 
 
 
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-04-2009
On Feb 4, 3:45*pm, joec...@gmail.com wrote:
> On Feb 4, 10:36*am, gob0...@googlemail.com wrote:
>
> > emails["J. Horvath"]="jhorv...@mail.com"; //#1
> > If the map already contains the key "J. Horvath", the current
> > associated value remains unchanged:

>
> > emails ["J. Horvath"]="newa...@com.net"; //#2 ,has no effect>
> > IMHO, this seems wrong. #2 should update the data_value of key "J.
> > Horvath" to "newa...@com.net".

>
> > 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

 
Reply With Quote
 
peter koch
Guest
Posts: n/a
 
      02-04-2009
On 4 Feb., 16:36, gob0...@googlemail.com wrote:
> 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
 
Reply With Quote
 
pasa@lib.hu
Guest
Posts: n/a
 
 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-05-2009
On Feb 4, 7:48*pm, p...@lib.hu wrote:
> ACCU reviews list as 'Not recommended'
>
> http://accu.org/index.php?module=boo...earch&rid=1170
>
> http://accu.org/index.php?module=boo...search&rid=294


Thanks for all your replies, very helpful and not only in C++...
Gob00st
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error reference in the guide of Excel GRL Computer Support 5 10-23-2005 03:29 PM
Visual Studio .Net Reference Guide John Vacha MCSD 0 11-19-2004 11:02 PM
Definitive DOM guide & reference? MeDoingWeb HTML 2 08-17-2004 06:24 PM
JSTL Quick Reference Guide WJ Java 2 07-15-2004 04:29 PM
CSS Quick Reference Guide WJ HTML 2 11-28-2003 09:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57