Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!apple!lsr From: lsr@Apple.com (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: C++ CString sample code Message-ID: <11904@goofy.Apple.COM> Date: 29 Jan 91 22:55:49 GMT References: <5672@rex.cs.tulane.edu> <11830@goofy.Apple.COM> Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 19 In article , rae@gpu.utcs.toronto.edu (Reid Ellis) writes: > > It shouldn't be const. If you are using operator+=() as defined > above, you do not have a const object, and a method shouldn't "make" > it const for no good reason. e.g., defining operator+=() as returning > a "const CString &" would make the following illegal: > > if((cstr += otherCstr)[12] == '\n') ... First, you aren't changing the object into a const object. You are simply affecting the result of operator+=. All you are doing is preventing more than 1 modification in the same statement. Not necessarily; it depends on the declaration of CString::operator[]. That method doesn't change the string, so it could be declared as a const member function. In that case, the construct above would be legal. Certainly, other constructs would be illegal (eg, str1 += str2 += str3). Larry