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