Path: utzoo!attcan!uunet!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!snorkelwacker!spdcc!merk!alliant!linus!luke.mitre.org!dsr From: dsr@luke.mitre.org (Douglas S. Rand) Newsgroups: comp.lang.c++ Subject: Re: Copying objects Keywords: Object copy constructor Message-ID: <111895@linus.mitre.org> Date: 27 Jun 90 13:40:05 GMT References: <18753@well.sf.ca.us> Sender: usenet@linus.mitre.org Reply-To: dsr@luke.mitre.org (Douglas S. Rand) Distribution: comp Lines: 31 Copying objects is lots of fun. You can consider a few problems/options. 1) Do subobject pointers get copied? or do the subobjects get duplicated and the new pointer assigned? 2) How do you handle method combination? Is each class responsible for the entire copy or does a child class ask its parent to copy the parent's data (note that this involves the extra bookeeping of explicitly calling the parent method (as AT&T won't admit that a symbol indicating 'super' is worth it). 3) Do you really want an exact copy? Maybe some instance vars need to be individual (like numerical identifiers). etc. etc. etc. In any case, use a virtual function for each class in the hierarchy and use a consistent style. You probably don't want to just duplicate the object. This is, BTW, why C++ doesn't provide a simple copy function (neither does CLOS in CommonLISP, and I can't remember whether St80 does). Douglas S. Rand Internet: Snail: MITRE, Burlington Road, Bedford, MA Disclaimer: MITRE might agree with me - then again...