Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!world!wmm From: wmm@world.std.com (William M Miller) Newsgroups: comp.lang.c++ Subject: Re: Distinguishing lvalue/rvalue operator[] Message-ID: <1991Mar5.021423.22117@world.std.com> Date: 5 Mar 91 02:14:23 GMT References: <1991Mar3.202134.17812@mathcs.sjsu.edu> <1991Mar4.054915.19566@mathcs.sjsu.edu> Organization: The World Public Access UNIX, Brookline, MA Lines: 25 horstman@mathcs.sjsu.edu (Cay Horstmann) writes: > I was thinking more about Joe Buck's suggestion to make the distinction > of lvalue/rvalue operator[] by returning an access class, and found another > snag. Suppose you have a variable size integer array and have operator[] > return an instance of class Access with functions > Access::operator=(int) > Access::operator int > as suggested. Then the statement > a[i]++ > will not execute. Of course not. (You wouldn't want it to, anyway -- presumably whatever you do in operator=() to handle lvalue access also needs to be done for ++, no?) The "Access" class is really acting as an enhanced functionality surrogate for the addressed member (enhanced functionality because it's supposedly doing different things for lvalue and rvalue accesses). That means that anything you want to do with the accessed array member, you must be able to do with an object of class Access. If you want to use ++, you need an Access::operator++(). If you want to do ".print()," as in your earlier posting, you need an Access::print(). It's really very straightforward -- you look at what you need to do with selected array elements and you put the appropriate support in the corresponding Access class. -- William M. Miller, Glockenspiel, Ltd. wmm@world.std.com