home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!math.fu-berlin.de!ira.uka.de!slsvaat!josef!kanze
- From: kanze@us-es.sel.de (James Kanze)
- Subject: Re: Overloading Operators
- In-Reply-To: krc@wam.umd.edu's message of Mon, 25 Jan 1993 17:48:19 GMT
- Message-ID: <KANZE.93Jan26175302@slsvdnt.us-es.sel.de>
- Sender: news@us-es.sel.de
- Organization: SEL
- References: <727392166snx@trmphrst.demon.co.uk> <C13BK9.Lr@frumious.uucp> <2215@celia.UUCP>
- <1993Jan25.174819.18445@wam.umd.edu>
- Date: 26 Jan 93 17:53:02
- Lines: 31
-
- In article <1993Jan25.174819.18445@wam.umd.edu> krc@wam.umd.edu (Kevin
- R. Coombes) writes:
-
- |> In article <2215@celia.UUCP> celia!gray@usc.edu (Steve Gray) writes:
- |> >A const reference differs in a very important way from a plain reference:
- |> >it clearly states that the member function has no side effects. One of
- |> >my (and others at R&H's) primary objections to using references is that
- |> >it means member functions can have un-obvious side effects on their parameters.
- |> >i.e. they can change the contents of a variable which was passed by value (as
- |> >far as the caller's syntax is concerned) and therefor should not be changed by
- |> >the member function.
- |> >
- |> >We have basically outlawed non-const references as being too dangerous. I
- |> >personally would have preferred that they not even be allowed in the language,
- |> >but I can understand why (given the syntax of the language) they are allowed.
-
- |> Have you also outlawed pointers (to non-const objects) as parameters?
-
- There is a very big difference between using a non-const reference and
- a non-const pointer as a parameter. In the case of the reference, the
- *only* place where it is documented that the function might change the
- parameter is in the function prototype, which is often quite far from
- where the function is being used. When the parameter is a pointer,
- however, the address of the parameter must be taken explicitely when
- the function is called, so someone reading the program can see
- immediately what the risks are.
- --
- James Kanze email: kanze@us-es.sel.de
- GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
- Conseils en informatique industrielle --
- -- Beratung in industrieller Datenverarbeitung
-