home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16226 < prev    next >
Encoding:
Text File  |  1992-11-14  |  2.1 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!boulder!happy.colorado.edu!srheintze
  3. From: srheintze@happy.colorado.edu
  4. Subject: Overload operator to concatenate Strings?
  5. Message-ID: <1992Nov13.111415.1@happy.colorado.edu>
  6. Lines: 38
  7. Sender: news@colorado.edu (The Daily Planet)
  8. Nntp-Posting-Host: happy.uccs.edu
  9. Organization: University of Colorado, Boulder
  10. Date: 13 Nov 92 11:14:15 MDT
  11. Lines: 38
  12.  
  13. I have a question concerning the book "C++ Programming Guidelines" 
  14. by Thomas Plum and Dan Saks.
  15.  
  16. On page 91 they discourage programmers from overloading operator||. They
  17. say "Because of any form of overloading destroys the 'sequenced' property
  18. of &&, || and comma, these operators should seldom (if ever) be overloaded."
  19.  
  20. What is the issue here? Are we talking about a maintainence programmer's 
  21. expectation of what operator|| or operator&& do or are we stating 
  22. that we should not overload operator|| (to concatentate strings, 
  23. for example) because the compiler might not evaluate the second 
  24. argument in all cases?
  25.  
  26. It seems logical to use some operator to concatenate strings. It seems to 
  27. me that character strings really should be defined as a vector of char since
  28. that is what they really are.  If we do that however, it is inappropriate to
  29. use operator+ because that means add two vectors.
  30.  
  31. I have considered using operator|| but Plum and Saks discourage it for reasons
  32. I don't completely understand.  It is intuitive to old PL/I programmers to use
  33. operator|| for character string concantenation. It seems logical to be
  34. consistent with something that already exists rather than invent some new
  35. notation.  However, I have my own reason for not using operator|| for character
  36. string concantenation:  I recently discovered there is no operator=||!
  37.  
  38. So I don't like operator+, neither I nor Saks like operator||, what should we
  39. use?  How about operator& for character string concatenation?
  40.  
  41. So, I would love to hear your recommendation on (1) what Plum and  Saks meant
  42. when they discourage the overloading of operator|| and (2) what you recommend
  43. be used to concatenate strings.
  44.  
  45.             Thanks,
  46.                     Sieg
  47.  
  48.   Thanks,
  49.      Sieg
  50.  
  51.