C++ Reference Guide mistake?

Discussion in 'C++' started by gob00st@googlemail.com, Feb 4, 2009.

  1. Guest

    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"]=""; //#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
     
    , Feb 4, 2009
    #1
    1. Advertising

  2. Guest

    On Feb 4, 10:36 am, wrote:
    > 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".


    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
     
    , Feb 4, 2009
    #2
    1. Advertising

  3. Guest

    On Feb 4, 3:45 pm, wrote:
    > On Feb 4, 10:36 am, wrote:
    >
    > > 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".

    >
    > 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
     
    , Feb 4, 2009
    #3
  4. peter koch Guest

    On 4 Feb., 16:36, 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
     
    peter koch, Feb 4, 2009
    #4
  5. Guest

  6. Guest

    , Feb 5, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WJ
    Replies:
    2
    Views:
    10,664
    Olaf Eilers
    Jul 15, 2004
  2. MeDoingWeb

    Definitive DOM guide & reference?

    MeDoingWeb, Aug 17, 2004, in forum: HTML
    Replies:
    2
    Views:
    492
    Isofarro
    Aug 17, 2004
  3. Replies:
    7
    Views:
    1,126
    Andy Dingley
    Jul 25, 2006
  4. ElesSar

    C reference guide

    ElesSar, Jan 18, 2004, in forum: C Programming
    Replies:
    6
    Views:
    416
    Xose Vazquez Perez
    Jan 20, 2004
  5. erebus-
    Replies:
    6
    Views:
    308
    Richard Bos
    Feb 23, 2004
Loading...

Share This Page