Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!fuchs From: fuchs@it.uka.de (Harald Fuchs) Newsgroups: comp.lang.c++ Subject: Re: friend operator +(l,r) vs. operator +(r) Message-ID: Date: 29 Nov 90 18:08:23 GMT References: <11759@hubcap.clemson.edu> <1990Nov21.053431.22340@actrix.co.nz> <1990Nov22.230835.26713@clear.com> Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG Lines: 22 rae@gpu.utcs.toronto.edu (Reid Ellis) writes: >rmartin@clear.com (Bob Martin) writes: >!foo fa,fb; >!int ia; >!... >!fb=ia+fa; // adding an int to a foo. >! >!If you use the foo::operator+(foo&) method, then the above statement >!will produce a compiler error since foo::operator+(foo&) requires that >!the left hand side of the + operator must be a foo. >Not necessarily. What if there existed "foo::operator int()" as well >as "foo:foo(int)"? Then the above would work fine. Yes, but it would not do what you might expect. It would convert fa to an int, perform _integer_ addition, and convert the result to a foo. foo::operator+(foo&) would not be called at all. -- Harald Fuchs ... *gulp*