Article View: comp.std.c++
Article #3219Re: Give operator. a chance
From: James Kanze US/ESC 60/3/141 #407...
Date: Sat, 03 Feb 1996 04:48
Date: Sat, 03 Feb 1996 04:48
58 lines
2995 bytes
2995 bytes
In article <4eqr6b$778@s3.iway.fr> 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.
|> Suppose first you overload operator+, then you overload operator. in
|> MyClass:
|> class MyClass {
|> private:
|> AnnotherClass* theOtherClass;
|> public:
|> AnnotherClass operator. ();
|> MyClass operator+ (int);
|> void Something_only_defined_in_MyClass ();
|> };
|> MyClass A;
|> A + 2; is equivalent with A.operator (2) and (A.operator.).operator (2)
No, at least not as I understand the proposal. A + 2 causes
MyClass::operator+ to be called, with &A as this, and 2 as the
argument. The operator.() function would only be called when a `.'
appears in the equation.
|> 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): (&A)->a_member is equivalent with
|> ((A.operator.).operator&)->a_member.
No, the type of `&A' is MyClass*. There is no operator.() defined for
this type, nor can there ever be. There is an operator-> defined, the
built in one.
If I write (&A)->, the compiler uses (the built-in) operator&, then
operator-> on the results. What makes you think it could do anything
else?
|> How can yu access Something_only_defined_in_MyClass ?
|> If operator. return theOtherClass, why don't you just write:
|> AnnotherClass* theOtherClass;
Because typically, `AnotherClass' is a proxy class (a smart
reference), the user doesn't even know about it, and cannot name it if
he is (since it will be declared private in the container class).
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
---
[ 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:
<9602020959.AA02291@lts.sel.alcatel.de>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: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> Message-ID: <9602020959.AA02291@lts.sel.alcatel.de> X-Original-Date: Fri, 2 Feb 96 10:59:13 +0100 Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 03 Feb 96 04:48:42 GMT Approved: fjh@cs.mu.oz.au In-Reply-To: Valentin Bonnard's message of 01 Feb 96 17:10:01 GMT Newsgroups: comp.std.c++ Subject: Re: Give operator. a chance References: <3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU> <4eqr6b$778@s3.iway.fr> Organization: GABI Software, Sarl. X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMRLpr+EDnX0m9pzZAQF3dAF+PmXFlU7G8vbGJeOrC3FszyFnAYQkWhIo 3fCDZB69k45JqJ8ceulfUYHmtdAm2MVH =+Qvf