Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: Lvalue checking for operator= ?? Message-ID: <10045@alice.UUCP> Date: 23 Oct 89 15:35:52 GMT References: <33433@cornell.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 39 In article <33433@cornell.UUCP>, deb@svax.cs.cornell.edu (David Baraff) writes: > Suppose you have a standard matrix class, which implements '+', > and also has its own assignment operator defined i.e. > matrix &matrix::operator= (matrix &m) > exists. Then, > matrix a, b, c; > ... > a+b = c; > appears to be legal. (As least it compiled under 1.2.) Is it legal under > 2.0 ? What does it really mean? Shouldn't the '=' operator be forced > to only accept an lvalue as its left-hand operand? How about making operator+ return a const matrix? Then you won't be able to assign to it. To tell the truth, I hadn't thought about this issue until this question forced me to do so. There are zillions of things like string classes out there that say extern String operator+(const String&, const String&); and apparently they really should say extern const String operator+(const string&, const String&); The point is that unless you say otherwise, you can't call operator= on behalf of a const object (well, 2.0 will let you get away with it but will give a warning). I think that's almost exactly what you want. -- --Andrew Koenig ark@europa.att.com