home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!slsvaat!josef!kanze
- From: kanze@us-es.sel.de (James Kanze)
- Subject: Re: Overload operator to concatenate Strings?
- In-Reply-To: jimad@microsoft.com's message of 17 Nov 92 01:07:44 GMT
- Message-ID: <KANZE.92Nov18124614@slsvdnt.us-es.sel.de>
- Sender: news@us-es.sel.de
- Organization: SEL
- References: <1992Nov13.111415.1@happy.colorado.edu> <1992Nov17.010744.18481@microsoft.com>
- Date: 18 Nov 92 12:46:14
- Lines: 37
-
- In article <1992Nov13.111415.1@happy.colorado.edu>, Jim Adcock writes:
-
- |> In article <1992Nov13.111415.1@happy.colorado.edu>
- |> srheintze@happy.colorado.edu writes:
-
- |> |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.
-
- |> If your target audience is old PL/I programmers, then use the ||
- |> notation.
-
- |> If your target audience is C++ programmers, then use + since that is
- |> the most common operator chosen to mean string cat in the C++ world.
- |> If you're writing an overloaded I/O operator use << and >> like
- |> iostreams -- these choices don't have to make much sense -- they've
- |> become established by convention. If you try to rethunk them now,
- |> you'll just be making your work gratuitously incompatible. Then
- |> again, why not get an existing class library with an existing string
- |> class? Why keep reinventing the [square] wheel?
-
- An additional reason governing the choice of operators is the
- precedence. While I sort of like '&' for concatenation, it has the
- wrong precedence for my tastes. a & b == c is a & (b == c) (illegal).
-
- For that matter, '&' and '|' also have the wrong precedence for bit
- operators. For this reason, in my SetOf classes, I not only overload
- them (since they are what I would expect for intersection and union),
- but also '*' and '+', less natural, but the right precedence.
- --
- James Kanze GABI Software, Sarl.
- email: kanze@us-es.sel.de 8 rue du Faisan
- 67000 Strasbourg
- France
-
-