comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: I'm facing an issue with: call to abstract procedure must be dispatching
Date: Tue, 8 Dec 2015 19:22:20 +0100
Date: 2015-12-08T19:22:20+01:00	[thread overview]
Message-ID: <rt3n7ox7u8lf$.1me9jljeld3bs$.dlg@40tude.net> (raw)
In-Reply-To: 5788b259-8886-4ee2-8c3d-7799abfd840e@googlegroups.com

On Tue, 8 Dec 2015 10:00:24 -0800 (PST), Serge Robyns wrote:

> On Tuesday, 8 December 2015 18:42:26 UTC+1, Dmitry A. Kazakov  wrote:
>> On Tue, 8 Dec 2015 09:24:58 -0800 (PST), Serge Robyns wrote:
>> In which relation is Do_Something to T_Abstract_Store?
>> 
>> 1. a primitive operation =
>>       has a separate implementation for each concrete type (from the class)
>> 2. class-wide operation =
>>       has same implementation for all types (from the class)
>> 
>> (anything else is a design fault)
>> 
>>> Inside that procedure I'm using the A_Store. This regardless how A_Store
>>> got implemented.
>> 
>> That sounds like #2. Then it must be declared as:
> 
> This is indeed Correct.  Thanks for the tip.  Now it works, well at least it compiles .....
> 
> procedure test is
> 
>    type T_Store is new T_Asbtract_Store with null record;
> 
>    overriding procedure Insert (Store  : in out T_Store;
>                                 Client : in     T_Client'Class) is
>    begin
>       null;
>    end Insert;
>    
>    procedure Do_Something (A_Store : in out T_Asbtract_Store'Class)
>    is
>       Client    : T_Client;
>    begin
>       A_Store.Insert (Client);
>    end Do_Something;        
>    
>    A_Store   : access T_Asbtract_Store;

Observe that exactly same logic applies here. You never ever use a
type-specific access type when you deal with whole class. Thus, without any
further considerations it must be this:

   A_Store : access T_Asbtract_Store'Class;

<rant on> In each instance you should clearly understand whether the code
deals with one specific type or with all class. Once you know that, you
express this knowledge in terms of types. One of the major Ada advantages
with respect to OO is that it is properly typed. The type of a specific
instance and the type of all instances from the class are two *different*
types. The language rejected your program not because of being cruel, but
because you used one type as if it were another. <rant off>

>    The_Store : aliased T_Store;
> 
> begin
>    A_Store := T_Asbtract_Store (The_Store)'Access;

Now, of course no explicit type conversion required:

  A_Store := The_Store'Access;

(Type conversion must raise alarm bells)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  reply	other threads:[~2015-12-08 18:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08 16:45 I'm facing an issue with: call to abstract procedure must be dispatching Serge Robyns
2015-12-08 16:59 ` G.B.
2015-12-08 17:04 ` Dmitry A. Kazakov
2015-12-08 17:24   ` Serge Robyns
2015-12-08 17:42     ` Dmitry A. Kazakov
2015-12-08 18:00       ` Serge Robyns
2015-12-08 18:22         ` Dmitry A. Kazakov [this message]
2015-12-08 20:21           ` Serge Robyns
2015-12-08 21:08             ` Dmitry A. Kazakov
2015-12-08 21:55               ` Serge Robyns
2015-12-08 22:43                 ` Serge Robyns
2015-12-08 22:55                   ` Jeffrey R. Carter
2015-12-09 23:03                     ` Randy Brukardt
2015-12-10  8:38                       ` Serge Robyns
2015-12-10 23:43                         ` Randy Brukardt
2015-12-09  8:48                 ` Dmitry A. Kazakov
2015-12-09 10:53               ` G.B.
2015-12-09 12:03                 ` Dmitry A. Kazakov
2015-12-09 13:42                   ` G.B.
2015-12-09 14:23                     ` Dmitry A. Kazakov
2015-12-08 22:55             ` Jeffrey R. Carter
2015-12-08 23:04               ` Serge Robyns
2015-12-08 23:42                 ` Jeffrey R. Carter
2015-12-09 13:40                 ` Jere
2015-12-09 13:48                   ` G.B.
2015-12-09 15:33                     ` Jere
2015-12-13 21:37                 ` Shark8
2015-12-14  2:20                   ` Jeffrey R. Carter
2015-12-15  7:26                     ` Shark8
2015-12-08 17:30 ` Jeffrey R. Carter
2015-12-08 17:48   ` Serge Robyns
2015-12-08 18:46     ` Jeffrey R. Carter
2015-12-08 20:28       ` Serge Robyns
2015-12-08 22:20     ` Simon Wright
replies disabled

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