home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16499 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.2 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!slsvaat!josef!kanze
  3. From: kanze@us-es.sel.de (James Kanze)
  4. Subject: Re: Overload operator to concatenate Strings?
  5. In-Reply-To: jimad@microsoft.com's message of 17 Nov 92 01:07:44 GMT
  6. Message-ID: <KANZE.92Nov18124614@slsvdnt.us-es.sel.de>
  7. Sender: news@us-es.sel.de
  8. Organization: SEL
  9. References: <1992Nov13.111415.1@happy.colorado.edu> <1992Nov17.010744.18481@microsoft.com>
  10. Date: 18 Nov 92 12:46:14
  11. Lines: 37
  12.  
  13. In article <1992Nov13.111415.1@happy.colorado.edu>, Jim Adcock writes:
  14.  
  15. |> In article <1992Nov13.111415.1@happy.colorado.edu>
  16. |> srheintze@happy.colorado.edu writes:
  17.  
  18. |> |I have considered using operator|| but Plum and Saks discourage it for reasons
  19. |> |I don't completely understand.  It is intuitive to old PL/I programmers to use
  20. |> |operator|| for character string concantenation. It seems logical to be
  21. |> |consistent with something that already exists rather than invent some new
  22. |> |notation.  
  23.  
  24. |> If your target audience is old PL/I programmers, then use the ||
  25. |> notation.
  26.  
  27. |> If your target audience is C++ programmers, then use + since that is
  28. |> the most common operator chosen to mean string cat in the C++ world.
  29. |> If you're writing an overloaded I/O operator use << and >> like
  30. |> iostreams -- these choices don't have to make much sense -- they've
  31. |> become established by convention.  If you try to rethunk them now,
  32. |> you'll just be making your work gratuitously incompatible.  Then
  33. |> again, why not get an existing class library with an existing string
  34. |> class?  Why keep reinventing the [square] wheel?
  35.  
  36. An additional reason governing the choice of operators is the
  37. precedence.  While I sort of like '&' for concatenation, it has the
  38. wrong precedence for my tastes.  a & b == c is a & (b == c) (illegal).
  39.  
  40. For that matter, '&' and '|' also have the wrong precedence for bit
  41. operators.  For this reason, in my SetOf classes, I not only overload
  42. them (since they are what I would expect for intersection and union),
  43. but also '*' and '+', less natural, but the right precedence.
  44. --
  45. James Kanze            GABI Software, Sarl.
  46. email: kanze@us-es.sel.de    8 rue du Faisan
  47.                 67000 Strasbourg
  48.                 France
  49.  
  50.