From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,741d9c75087d538f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-09 10:03:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Message-ID: <3EE4BA52.9000000@cogeco.ca> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Cloning a Class Wide Data Type with "new"? References: <3EE097D5.2010901@cogeco.ca> <5a59d6a9.0306061038.18a1072@posting.google.com> <5a59d6a9.0306061505.72b5f19d@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 09 Jun 2003 12:48:18 -0400 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1055177297 198.96.223.163 (Mon, 09 Jun 2003 12:48:17 EDT) NNTP-Posting-Date: Mon, 09 Jun 2003 12:48:17 EDT Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:38865 Date: 2003-06-09T12:48:18-04:00 List-Id: Thank you everyone that replied to the "challenge". Anh_Vo wrote: >>Base_Class is not a real type. Base_Type and Derived_Type are real >>types. Thefore, either one of them should be used. I assume >>Derived_Type was your intention in this case. Otherwise, explicit >>conversion is needed. Both cases are shown below. >> >>Cloned : Base_Access := new Derived_Type' (Orig); -- case 1 >> >>Cloned : Base_Access := new Base_Type' (Base_Type (Orig)); -- case 2 >> >>A. Vo > > > My fingers were ahead of my thought. What I mean was that Base_Class > is class wide type while Base_Type and Derived_Type are not. That > means there should be case 3 for it. > > Cloned : Base_Access := new Base_Class' (Base_Class (Orig)); -- case > 3 > > By the way, I made another error while typing the word Therefore. But > it turned out to be Thefore. Yes, as pointed out by yourself and others, the above solution works. Boiling it down to avoid using Base_Class (which is just Base_Type'Class), this may be more easily(?) understood as: Cloned : Base_Access := new Base_Type'Class'(Base_Type'Class(Orig)); which I guess makes sense. "Orig" is a specific type, so you need to "convert" it to a class wide type to be used as the "prototype" to be cloned. Then the "new" operator needs to be told to return a class wide type, so I guess as clumsy as it looks, this is perhaps the only conceivable way that it should be specified (ie. it makes sense). Thanks everyone, Warren. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg