Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!agate!darkstar!ucschu.ucsc.edu!ericg From: ericg@ucschu.ucsc.edu (Eric Goodman) Newsgroups: comp.lang.c++ Subject: Re: Copying objects Message-ID: <4853@darkstar.ucsc.edu> Date: 2 Jul 90 23:48:26 GMT References: <18753@well.sf.ca.us> Sender: usenet@darkstar.ucsc.edu Distribution: comp Organization: Humanities Division, UC Santa Cruz Lines: 29 In article <18753@well.sf.ca.us> mccarthy@well.sf.ca.us (Patrick McCarthy) writes: > In other words, suppose you have a class called Base, and two classes > Derived_1 and Derived_2 which inherit from Base. Suppose further that p > and q are of type Base *. In order to make p point to a copy of q using > q's copy constructor, you would have know q's type in advance as > follows: A virtual overloaded operator= should work (I'm assuming that virtual operators are legal); the problem is that you would have to define it backwards: Class Base{ public: virtual Base operator=(Base) { ... } }; insures that the left operand of the = is of the correct type, so *p=*q; // could be used to copy *p into *q with p's type insured. I don't see how you could do this to copy in the ordinary fashion, though so this may be useless. Eric Goodman Humanities Division University of California, Santa Cruz ericg@ucschu.ucsc.edu ericg@ucschu.bitnet Eric_Goodman.staff@macmail.ucsc.edu ...!ucbvax!ucscc!ucschu!ericg