🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3250

Re: Give operator. a chance

#3250
From: Claus A. Faerber
Date: Mon, 05 Feb 1996 22:59
51 lines
1878 bytes
IMO there's a better way than 'operator.()':

Simply say: 'If a class member identifier is not found  
within an object, all possible cast operators are scanned in  
order to find a conversion to an object of a class  
containing a member with this identifier.'

Eg.:

class A{
public: void A();
        void C();
}

class B{
public:
        void B();
        void C();
        void D();
}

class C{
        A* pA;
        B* pB;
public:
        void D();

        A& operator A&() { return *pA; };
        B& operator B&() { return *pB; };
}

//

C c;

c.A();  // calls ((A&)c).A();
c.B();  // calls ((B&)c).B();

c.C();  // calls ((A&)c).C();, as operator A& is first

c.D();  // calls c.D();, as D() is already member of C

Claus

------------------------------------------------------------------------
Claus Andre Faerber - claus@faerber.muc.de - http://www.muc.de/~cfaerber
------------------------------------------------------------------------
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID: <62HLdPo3cDB@faerber.muc.de>
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
From: claus@faerber.muc.de (Claus A. Faerber)
Newsgroups: comp.std.c++
Subject: Re: Give operator. a chance
Date: 05 Feb 1996 14:59:10 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <62HLdPo3cDB@faerber.muc.de>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Mon, 5 Feb 1996 01:00:00 +0100
In-Reply-To: <3102AD11.1663@et.se>
X-Mailer: CrossPoint v3.1 R/B17071
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMRaL0Ey4NqrwXLNJAQHgKQH9G9ZiCYu4kbvigXppjwBEkCyhbyrwBWGq
 h8htHtxf66+saixZgQlqueXUlaBJNdwWWzlJgKCRhtA0hOQAUqA3Hg==
 =U0MR
Originator: austern@isolde.mti.sgi.com