home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Answers on a postcard...
- Message-ID: <1992Sep13.160033.7735@taumet.com>
- Organization: TauMetric Corporation
- References: <92254.104002KKEYTE@ESOC.BITNET> <1992Sep10.174914.838@taumet.com> <92255.112151KKEYTE@ESOC.BITNET> <1992Sep11.174716.3699@taumet.com> <92256.150512KKEYTE@ESOC.BITNET>
- Date: Sun, 13 Sep 1992 16:00:33 GMT
- Lines: 43
-
- Karl Keyte <KKEYTE@ESOC.BITNET> writes:
-
- >... In overloading, for
- >example, the '+' operator for one of my own classes, I would try to provide
- >functionality which fits with the usual understanding of the operator. In
- >providing '+' for "strings" I would hope to offer concatenation rather than
- >truncation with the '+' operator. That works quite well. If I require
- >something which is unrelated to any operator I would rather not overload
- >but provide a member function...
-
- This is a very commendable programming style, and I recommend it to
- everyone. It isn't a language rule, however, and probably would not
- be enforceable by a compiler if it were.
-
- >To do what I have just described with the comma-operator in C++ is not
- >possible. [ in the sense of preserving order of evaluation ]
-
- Just what we have been saying. In consequence, I suggest that you
- do not overload the comma, but use a non-operator function instead.
-
- If a major concern is preserving order of evaluation, then continue
- to use the comma just that way and don't overload it. If you want
- to use the comma as a shorthand for a function call, then accept the
- function-call semantics.
-
- It would be possible to change the rules so that order of evaluation
- was preserved for overloaded versions of operators "&&", "||", and ",".
- Any proposal to do so would have to show some good reason why the
- change is needed. Personally, I've never seen any example of code
- which was improved by using an overloaded comma (which of course
- doesn't mean there is no such code).
-
- In the case of "&&" and "||", another solution might be to provide
- operator void*() for the classes instead, and not overload the logical
- functions. If that doesn't solve the problem, then it seems to me
- that the overloaded logical operators are violating the principle of
- acting like their built-in versions. For example, "A && B" doesn't
- do anything to A or B, but treats each as a zero/non-zero value. You
- don't need to overload "&&" to get that effect.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-