Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!olivea!orc!bu.edu!husc6!ngo From: ngo@tammy.harvard.edu (Tom Ngo) Newsgroups: comp.lang.c++ Subject: Tricky question answered Message-ID: Date: 25 Sep 90 19:46:27 GMT Sender: news@husc6.harvard.edu Distribution: comp Organization: Harvard Chemistry Department Lines: 32 Earlier today, I wrote: ngo> I would appreciate any advice about the following situation. ngo> [...] ngo> This means that inside Collector::memorize() I must invoke "new B"... ngo> but that is obviously not going to be enough, since a B cannot hold ngo> all of the information in, say, a B1. Are there any suggestions on ngo> how to handle this? I have thought of an answer that satisfies me: class B should contain a virtual function called clone() which, when invoked with any of the derived classes, invokes new in a class-specific manner: B1* B1::clone(void) const { return new B1(class_specific_arguments); } So my method Collector::memorize(B *p) can do B *q = p->clone(); to get durable copies of the objects to which p points. Sorry to waste bandwidth while thinking aloud. If I still get replies and they are different from this idea, I might still post a summary. -- Tom Ngo ngo@harvard.harvard.edu 617/495-1768 lab number, leave message