From: Simon Wright <simon@pushface.org>
Subject: Re: A good program that not compile
Date: Wed, 21 May 2014 16:58:43 +0100
Date: 2014-05-21T16:58:43+01:00 [thread overview]
Message-ID: <lyfvk36s3w.fsf@pushface.org> (raw)
In-Reply-To: llic43$kge$1@speranza.aioe.org
Victor Porton <porton@narod.ru> writes:
> Simon Wright wrote:
>
>> Victor Porton <porton@narod.ru> writes:
>>
>>> The following does not compile.
>>
>> For very good reasons.
>>
>> Obtain_Handle(File_Handle) ought to be a function!
>> It should take an in parameter, not in out!
>>
>> I take it your point is that you want to be able to declare
>>
>> function Obtain_Handle(Object: Abstract_Handle) return Integer
>> is abstract;
>>
>> but I find that (with the latest compilers) this works:
>>
>> function Obtain_Handle(Object: Abstract_Handle) return Integer
>> is (raise Program_Error);
>>
>> with the slight disadvantage of postponing failure to run time (which
>> might happen anyway with your proposal).
>
> I have rewritten it with your suggestions. Now it does compile, but instead
> as of to work as intended (Assigning 123 to the Handle) it raises
> Program_Error.
You have written (as before)
overriding procedure Initialize(Object: in out Abstract_Handle) is
begin
Object.Handle := Obtain_Handle(Object);
end;
but I wrote
overriding procedure Initialize(Object: in out Abstract_Handle) is
begin
Object.Handle := Obtain_Handle(Abstract_Handle'Class (Object));
-- ^^^^^^^^^^^^^^^^^^^^^^^ ^
-- use view conversion to get dispatching
end;
In your case, the call to Obtain_Handle is *not* dispatching. You need a
classwide object (or access) to get dispatching; as you see, you can get
this by a view conversion.
prev parent reply other threads:[~2014-05-21 15:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 13:05 A good program that not compile Victor Porton
2014-05-21 13:49 ` Simon Wright
2014-05-21 14:10 ` Victor Porton
2014-05-21 14:24 ` Victor Porton
2014-05-21 15:58 ` Simon Wright [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