Newsgroups: comp.lang.c++ Path: utzoo!censor!geac!alias!earth!rae From: Reid Ellis Subject: Re: friend operator +(l,r) vs. operator +(r) Message-ID: Sender: Reid Ellis Reply-To: Reid Ellis Organization: Alias Research, Inc. Toronto ON Canada References: <11759@hubcap.clemson.edu> <1990Nov21.053431.22340@actrix.co.nz> <1990Nov22.230835.26713@clear.com> Date: 27 Nov 90 05:14:58 GMT 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. [Personal opinion follows] I don't agree with the idea that the result of adding two objects of different type should return any arbitrary type, as defined by a global function "operator+(type1, type2)". Rather, I have a "gut feel" that if I add an orange to an apple, it is up to the apple to decide what to do with it. I guess this comes from English where, for example, you add an element to a set [resulting in a new set] but you don't add a set to an element.. Does anyone else think that operator+(const type1 &, const type2 &); should have a return type of type1 at all times? [end opinion] Reid -- Reid Ellis 176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu CDA0610@applelink.apple.com || +1 416 446 1644