Path: utzoo!attcan!uunet!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: operator[] Keywords: array C++ overloaded Message-ID: Date: 22 Oct 90 19:00:10 GMT References: <1442@ziggy.EDU> Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG Lines: 31 card@ziggy.EDU (James Card) writes: >Is there any way of telling which side of the '=' a class [] >operator is on? I was thinking of a possible application in which >a disk file could be used as a virtual array. A constructor could >be used to open the "virtual" array and a destructor would be used >to close the "virtual" array. Using this scheme, object[] operations >appearing on the left hand side of the '=' would cause a write to the >associated file, and object[] appearing on the right hand side of the >'=' would cause a read of the disk array. class file; class fileref { friend file; file& f; unsigned long ix; fileref (file& ff, unsigned long i): f (ff), ix (i) {} public: fileref& operator= (char); // left hand side operator char (); // right hand side }; class file { public: file (const char* name); ~file (); fileref operator[] (unsigned long ix) { return fileref (*this, ix); } }; -- Harald Fuchs ...