Xref: utzoo comp.lang.c++:12021 comp.std.c++:684 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!tmipe0!fuchs From: fuchs@tmipe0.telematik.informatik.uni-karlsruhe.de (Harald Fuchs) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Re: distinguishing operator[] on left and right Message-ID: Date: 5 Mar 91 03:02:32 GMT References: <1991Feb28.212419.20920@ndl.com> <1991Mar2.000705.3496@mathcs.sjsu.edu> <11634@pasteur.Berkeley.EDU> <1991Mar4.211036.9508@am.dsir.govt.nz> Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG Lines: 19 robert@am.dsir.govt.nz (Robert Davies) writes: >Currently (in Turbo C++ or Glockenspiel C++; my version of Zortech can't >distinguish between the 2 versions) you need to write > char c = ((const string)g)[3]; >to get the second version. Which is a bit messy. >But wouldn't it be reasonable for the second version to be the default if the >compiler can tell that the operation won't affect the value of g? Won't work. In general, the only way for a compiler to know about constness is just by declaring a member function const. A non-const operator[] is legal and sometimes even reasonable. Const vs. non-const and LHS vs. RHS are completely different matters. -- Harald Fuchs