Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!bionet!agate!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.lang.c++ Subject: Virtual Memory from C++. Summary: Overloading [] two ways. Message-ID: <1054@helios.ee.lbl.gov> Date: 4 Oct 88 07:47:32 GMT Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 38 Hello. I am still getting my bearings in C++ and decided that as a first attempt at class construction I would write a file class of a slightly different flavor than the ostream model presented in Stroustrap's book. My model is that of an array of bytes: #include #include class file { FILE *f; // pointer to a file variable char buf[BUFSIZ]; char opened; // has file been opened? long _where; int error; public: file(char*, char*); ~file(void); char& operator[](long); char operator=(char); }; I can get to byte n of the file by specifying: file f("foo","r+"); /* fopen style call */ long n=100000; char c=f[n]; Now, what if I want to set the value of byte n? i.e., f[n]=c; Do I make operator[] a friend of class file and write two versions, one with class file as first argument, and one with second? Can what I want to do be done? Thanks, Patrick Beard Lawrence Berkeley Laboratory beard@ux1.lbl.gov