Path: utzoo!mnetor!uunet!mcvax!cernvax!ethz!marti From: marti@ethz.UUCP (Robert Marti) Newsgroups: comp.lang.c++ Subject: Re: Operator overloading considered harmful Message-ID: <281@bernina.UUCP> Date: 13 Jan 88 10:09:08 GMT References: <240@vsi1.UUCP> <4538@watdragon.waterloo.edu> Organization: ETH Zuerich, Switzerland Lines: 33 Summary: *function* overloading considered just as harmful ... In article <4538@watdragon.waterloo.edu>, gvcormack@watdragon.waterloo.edu (Gordon V. Cormack) writes: > In article <240@vsi1.UUCP>, steve@vsi1.UUCP (Steve Maurer) writes: > (as an indictment of operator overloading). > > > foo(int i) { i #= i ^^ i @& i; } > > > > what does it do?? You will never know unless you start digging > > through miles of include/lib files. > > Would it be clearer as > > foo(int i) { glorp_assign(i, fred(xyz_arrows(i,i),nerf(i))); } Disregarding the fact that Maurer's example is not legal in C++, both examples suffer from the same problems if (operator or function) overloading is used: 1. As mentioned in Maurer's original posting, you may have to search your source files for the appropriate operator or function definitions for quite a while. 2. Overloading may unintentionally defeat type checking. Personally, I think the (more restricted) form of overloading you get by subclassing and inheritance is all you really need. The argument for operator overloading -- namely that it is nice to use an operator such as + for adding complex numbers, vectors, etc -- is just not good enough for me. After all, this is just syntactic sugaring! -- Robert Marti Phone: +41 1 256 52 36 Institut fur Informatik ETH Zentrum/SOT CSNET/ARPA: marti%ifi.ethz.ch@relay.cs.net CH-8092 Zurich, Switzerland UUCP: ...uunet!mcvax!ethz!marti