Xref: utzoo comp.lang.c++:11948 comp.std.c++:656 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!world!decwrl!apple!netcom!sjsumcs!horstman From: horstman@mathcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Re: distinguishing operator[] on left and right Message-ID: <1991Mar2.000705.3496@mathcs.sjsu.edu> Date: 2 Mar 91 00:07:05 GMT References: <1991Feb28.212419.20920@ndl.com> Organization: San Jose State University - Math/CS Dept. Lines: 23 In article <1991Feb28.212419.20920@ndl.com> gilley@ndl.com (Greg Gilley) writes: >Is there any way to distinguish when the operator[] is used as an >lvalue as opposed to an rvalue? > Surely I am not the first one to propose this one, but here goes anyway. Just as pre- and postincrement operator++ are distinguished by a hidden int argument, could this not be done for lvalue and rvalue operator[]? I.e. const X& operator[]( int ) and X& operator[]( int, int )? The second int is always 0. If the second operator is not present, the first one is taken for both lvalues and rvalues. Points to consider: (1) It is ugly as hell (2) It has precedent (operator++) (3) It won't break existing code (4) It does not use the keyword "static" in unusual ways. Cay