Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!usc!ucla-cs!rutgers!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: Lvalue checking for operator= ?? Message-ID: <10047@alice.UUCP> Date: 24 Oct 89 06:24:43 GMT References: <33433@cornell.UUCP> <10045@alice.UUCP> <874@mit-amt.MEDIA.MIT.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 45 In article <874@mit-amt.MEDIA.MIT.EDU>, peter@mit-amt.MEDIA.MIT.EDU (Peter Schroeder) writes: > How do I tell the compiler that `*this' > is const with respect to some operation? > After all that is really what I need in the above case?! You put `const' in the appropriate place in the member function declaration. For example: class Foo { public: int getsize() const; void setsize(int); // ... }; int Foo::getsize() const { int x; // ... return x; } void Foo::setsize(int x) { // ... } Here, the instances of `const' in Foo::getsize() say that *this is a const inside getsize but not in setsize. Thus: main() { Foo f; const Foo cf; f.setsize(3); // OK int n = f.getsize(); // OK n = cf.getsize(); // OK cf.setsize(7); // error -- cf is const } -- --Andrew Koenig ark@europa.att.com