Article View: comp.std.c++
Article #3217Re: Give operator. a chance
From: Fergus Henderson
Date: Sat, 03 Feb 1996 04:41
Date: Sat, 03 Feb 1996 04:41
44 lines
2611 bytes
2611 bytes
Valentin Bonnard <bonnardv@pratique.fr> writes: >First of all, I suppose there is no difference bewten A + B, A.operator+ (B) >and A.plus (B) when operator+ is defined as plus. No, not in the semantics which Jim Adcock proposed and which I implemented. The rule is very simple: you invoke the `operator . ()' function, if any, if and only if the source code contains a `.'. So `A.operator+(B)' and `A.plus(B)' will invoke `operator . ()', but `A + B' will not. >Suppose first you overload operator+, then you overload operator. in MyClass: [...] >MyClass A; > >A + 2; is equivalent with A.operator (2) and (A.operator.).operator (2) Nope, according to Jim Adcock's proposal, `A + 2' would not invoke the user-defined `operator . ()' function. See above. >You can't even write (&A)->Something_only_defined_in_MyClass () in order to >access Something_only_defined_in_MyClass (which is only defined for MyClass): Nope, according to Jim Adcock's proposal, for your example you are free to do so. >Note that A.m _is equivalent_ (provided that operator. is not overloaded in >AnnotherClass) with (&A)->m. Nope, according to Jim Adcock's proposal that is not necessarily true either. This is just like `x++' not necessarily being equivalent to `x = x + 1' if you have overloaded `operator ++'. With Jim Adcock's proposal, if you overload `operator .', you can make the equivalence hold, by also overloading `operator &' to return a smart pointer class. Without his proposal, if you overload `operator &', in the general case there is no way to make the equivalence hold. -- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3 --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9602020715.21371@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU> <4eqr6b$778@s3.iway.fr>Show Full Headers
Complete Article Headers
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Message-ID: <9602020715.21371@mulga.cs.mu.OZ.AU> X-Original-Date: Fri, 2 Feb 1996 18:15:24 +1100 Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 03 Feb 96 04:41:29 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Give operator. a chance Organization: Computer Science, University of Melbourne, Australia References: <3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU> <4eqr6b$778@s3.iway.fr> X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMRLnhuEDnX0m9pzZAQG6pgF7BWEySxerVKEcSqvqkDmV/fIhHy//sp6b pYaDg/dNn2f0kk77Js8NRjJDJ10IWZTg =KUYH