comp.lang.ada
 help / color / mirror / Atom feed
* Cloning a Class Wide Data Type with "new"?
@ 2003-06-06 13:32 Warren W. Gay VE3WWG
  2003-06-06 15:34 ` Jean-Pierre Rosen
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Warren W. Gay VE3WWG @ 2003-06-06 13:32 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-06-09 16:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-06 13:32 Cloning a Class Wide Data Type with "new"? Warren W. Gay VE3WWG
2003-06-06 15:34 ` Jean-Pierre Rosen
2003-06-06 17:15   ` Warren W. Gay VE3WWG
2003-06-06 18:11 ` David C. Hoos
2003-06-06 18:18 ` Marc A. Criley
2003-06-06 18:38 ` Anh_Vo
2003-06-06 23:05   ` Anh_Vo
2003-06-09 16:48     ` Warren W. Gay VE3WWG

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox