Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ulysses!hector!jss From: jss@hector.UUCP (Jerry Schwarz) Newsgroups: comp.lang.c++ Subject: Re: "Inheritance" of operator=() Keywords: user error or cfront error? Message-ID: <11519@ulysses.homer.nj.att.com> Date: 11 May 89 15:59:03 GMT References: <863@ethz.UUCP> Sender: netnews@ulysses.homer.nj.att.com Reply-To: jss@hector.UUCP (Jerry Schwarz) Organization: AT&T Bell Laboratories Lines: 40 In article <863@ethz.UUCP> marti@ethz.UUCP (Robert Marti) asks some questions about inheritance of assignment. Assignment is special because it is defined for all classes, (thus it never needs to be inherited). But the meaning of assignment has changed between 1.2 and 2.0. In 1.2 the synthesized assignment operator was always "bitwise copy". This was seen to be wrong and in 2.0 assignment is defined to be "recursive". The example is something like struct B { // some data members B& operator=(B&) ; } ; struct D : public B { // some more data members } ; void f() { D d1, d2 ; d1 = d2 ; // what should happen here? } Note that it doesn't make much sense to just "inherit" assignment because that would mean that the added members of D wouldn't participate in assignment of D. Since 1.2 didn't implement a "recursive" assignment, and a bitwise copy would clearly be wrong. It insisted that if assignment was defined in the base class that it also be defined in the derived class. In 2.0 the synthesized assignment operation usually "does the right thing" so this restriction is not imposed. Jerry Schwarz AT&T Bell Labs, Murray Hill