Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Copying objects Message-ID: <304@taumet.com> Date: 4 Jul 90 17:27:35 GMT References: <18753@well.sf.ca.us> <4853@darkstar.ucsc.edu> <55612@microsoft.UUCP> Reply-To: steve@taumet.UUCP (Stephen Clamage) Distribution: comp Organization: Taumetric Corporation, San Diego Lines: 26 In article <55612@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes: >Interestingly, operator= has the unique characteristic of being >virtual but not inherited! Can someone explain what this is suppose >to mean? If a derived class inherits an operator=, what happens to the extra fields in the derived class? If the programmer goes to the trouble of writing operator=, the compiler must assume that something special, beyond memberwise assignment, is required. The compiler cannot guess what this is, so leaves it to the programmer. Hence, operator= is not inherited. (We could argue that if the derived class has no data members it is OK to inherit the operator=, but it is simpler to go with the ARM and say it is not inherited.) Virtual is a separate concept, and a virtual operator= merely assures that the correct operator is called in the case of polymorphic objects. The ARM states that the default operator= (memberwise assignment) is generated if (among other things) its address is taken. If a derived class needs a virtual operator= and the programmer does not declare one, the compiler should generate the default version and put it in the virtual table. If this didn't happen, it may be a bug in the compiler, or a compiler written to an earlier version of C++. -- Steve Clamage, TauMetric Corp, steve@taumet.com