From: Victor Porton <porton@narod.ru>
Subject: Re: abstract types and subprograms
Date: Tue, 20 May 2014 15:28:29 +0300
Date: 2014-05-20T15:28:29+03:00 [thread overview]
Message-ID: <llfhpb$ka4$1@speranza.aioe.org> (raw)
In-Reply-To: 7puqh5yz4dyf.pov2dgfr2ky$.dlg@40tude.net
Dmitry A. Kazakov wrote:
> On Tue, 20 May 2014 13:22:30 +0300, Victor Porton wrote:
>
>> By the philosophy of programming From_Handle should be non-abstract but
>> return an abstract object, and From_Handle should be automatically
>> overridden for descendants non-abstract objects.
>>
>> What is wrong?
>
> You cannot automatically override without knowing the implementation,
> which you don't in advance. If you know it, then it is same for all class.
> See below.
>
>> -- rdf-base.ads
>> with Ada.Finalization;
>> with Interfaces.C.Pointers;
>>
>> package RDF.Base is
>>
>> -- Internal
>> type Dummy_Record is null record;
>>
>> -- Internal
>> type Dummy_Record_Access is access Dummy_Record;
>>
>> type Base_Object is abstract new Ada.Finalization.Limited_Controlled
>> with
>> private;
>>
>> function Get_Handle(Object: Base_Object) return Dummy_Record_Access
>> with
>> Inline;
>>
>> function From_Handle(Handle: Dummy_Record_Access) return Base_Object
>> with
>> Inline;
>
> function From_Handle(Handle: Dummy_Record_Access) return
> Base_Object'Class;
>
> Logically, a handle can point on an object of any type derived from
> Base_Object, so it is a class.
But can this:
function From_Handle(Handle: Dummy_Record_Access) return Base_Object is
(Ada.Finalization.Limited_Controlled with Handle=>Handle);
be implemented if the return type changes to Base_Object'Class?
It seems for me that I should define it as above and override From_Handle
for each derived tagged type.
It seems that returning Base_Object'Class wouldn't magically make it work
(without explicit override).
Or can it be done implementing Frorm_Handle only once (for Base_Object) with
automatic changing its signature for derived tagged types?
--
Victor Porton - http://portonvictor.org
next prev parent reply other threads:[~2014-05-20 12:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-20 10:22 abstract types and subprograms Victor Porton
2014-05-20 10:51 ` mockturtle
2014-05-20 11:45 ` Victor Porton
2014-05-20 16:27 ` Robert A Duff
2014-05-20 19:52 ` Dmitry A. Kazakov
2014-05-24 18:49 ` Robert A Duff
2014-05-24 19:41 ` Dmitry A. Kazakov
2014-05-20 11:55 ` Dmitry A. Kazakov
2014-05-20 12:28 ` Victor Porton [this message]
2014-05-20 14:11 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox