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,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-06 06:47:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!cyclone.bc.net!news.uunet.ca!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Message-ID: <3EE097D5.2010901@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: Cloning a Class Wide Data Type with "new"? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 06 Jun 2003 09:32:05 -0400 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1054906325 198.96.223.163 (Fri, 06 Jun 2003 09:32:05 EDT) NNTP-Posting-Date: Fri, 06 Jun 2003 09:32:05 EDT Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:38759 Date: 2003-06-06T09:32:05-04:00 List-Id: I havn't had much time to research this one yet, but I've got stuck trying to clone a class wide type this morning, on my way to work. A sample program is provided below. I need to be able to allocate and then copy an arbitrary tagged type (based upon a base type) into the newly allocated object. There's gotta be a way to do this.. I just can't remember it! The problem is the operation of the form of : Cloned : Base_Access := new Base_Class'(Orig); Here is a sample program that distills the problem: with Ada.Text_IO; use Ada.Text_IO; procedure TProg is type Base_Type is tagged record V : Integer; end record; type Base_Access is access all Base_Type'Class; subtype Base_Class is Base_Type'Class; type Derived_Type is new Base_Type with record Z : Natural; end record; -- This is the original object to be cloned Orig : Derived_Type := ( V => 32, Z => 99 ); -- This is a local copy (easy) Copied : Base_Class := Orig; -- Allocate Cloned to be same as Orig (the problem) Cloned : Base_Access := new Base_Class'(Orig); begin Put_Line("Cloned.V = " & Cloned.V'Img); end TProg; TIA, Warren. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg