Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: comp.lang.c++ Subject: Re: virtual constructors Message-ID: <2435@mmintl.UUCP> Date: Tue, 29-Sep-87 17:09:52 EDT Article-I.D.: mmintl.2435 Posted: Tue Sep 29 17:09:52 1987 Date-Received: Mon, 5-Oct-87 08:21:57 EDT References: <895@saturn.ucsc.edu> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT. Lines: 28 Keywords: constructors, derived In article <895@saturn.ucsc.edu> conrad@jupiter.ucsc.edu (Al Conrad) writes: >Virtual constructors are not allowed. So if I need a a copy >of a particular object which has derived classes, how do I >do it? For example: rectangle, circle, line, etc. are derived >classes of the base class *shape*. Now I want to make a copy >of a given shape. class shape { virtual shape * copy(); } class rectangle : public shape { shape * copy() { rectangle * answer = new rectangle; [copy this]; return answer; } } If you really want a constructor, you can now add in class shape: shape(shape * original) {this = original->copy()}; Otherwise, you can just use the copy function. -- Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108