comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: Cloning a Class Wide Data Type with "new"?
Date: Mon, 09 Jun 2003 12:48:18 -0400
Date: 2003-06-09T12:48:18-04:00	[thread overview]
Message-ID: <3EE4BA52.9000000@cogeco.ca> (raw)
In-Reply-To: 5a59d6a9.0306061505.72b5f19d@posting.google.com

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




      reply	other threads:[~2003-06-09 16:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
replies disabled

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