🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1827

Re: Usage of STL maps with pointers to member functions

#1827
From: Herb Sutter
Date: Wed, 23 Aug 1995 15:25
30 lines
1554 bytes
admin@rzaix13.uni-hamburg.de (Bernd Eggink) wrote:
>Gabriel Sanchez Gutierrez (gsg@sema.es) wrote:
>>  #include <iostream.h>
>>  #include <map.h>
>
>>  typedef char* string;
    ^^^^^^^^^^^^^^^^^^^^
Very bad.

>You are comparing pointers instead of strings. Add
>
>  struct less<string>
>  {
>	bool operator()(string a, string b) { return strcmp(a, b) < 0; }
>  };
>
>and it will work.

Typedef'ing "char*" to "string" is dangerous and misleading, since "string" 
already exists in the language.  In fact, removing the typedef should solve 
the original problem and make the program work properly!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter                 2228 Urwin, Ste 102         voice (416) 618-0184
Connected Object Solutions  Oakville ON Canada L6L 2T2    fax (905) 847-6019

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <41fh8j$kgc@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: herbs@interlog.com (Herb Sutter)
Newsgroups: comp.std.c++
Subject: Re: Usage of STL maps with pointers to member functions
Date: 23 Aug 1995 15:25:07 GMT
Organization: Daystar Software Systems Design Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <41fh8j$kgc@engnews2.Eng.Sun.COM>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
Content-Length: 831
X-Lines: 26
Originator: clamage@taumet