comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: What makes a procedure call 'dispatching' in Ada?
Date: Fri, 20 Nov 2009 14:27:14 +0100
Date: 2009-11-20T14:27:14+01:00	[thread overview]
Message-ID: <hnu4yrsf2d2d.1v1o4ujm3sccp$.dlg@40tude.net> (raw)
In-Reply-To: he64pl$d8i$1@nntp.ilk.net

On Fri, 20 Nov 2009 14:15:33 +0100, Markus Schoepflin wrote:

> I'm trying to fell may way around object oriented Ada programming, and I 
> think I must be missing something absolutely basic.

> Please consider the following package:
> 
> ---%<---
> package FOOS is
> 
>     type FOO is abstract tagged null record;
> 
>     procedure P (THIS : in FOO);
>     procedure A (THIS : in FOO) is abstract;
> 
> end FOOS;
> 
> package body FOOS is
> 
>     procedure P (THIS : in FOO)
>     is
>     begin
>        A (THIS);
>     end;
> 
> end FOOS;
> --->%---
> 
> When trying to compile this, I get:
> 
> foos.adb:6:07: call to abstract function must be dispatching
> gnatmake: "foos.adb" compilation error
> 
> What is the compiler trying to tell me here? And how do I go about calling 
> abstract procedures?

It tells you that the type of THIS is FOO, so you cannot call to A, because
A is not defined on FOO.

If P is to be defined in terms of any type from the class FOO, then P has
to be declared differently (class-wide):

package FOOS is
    type FOO is abstract tagged null record;
    procedure P (THIS : in FOO'Class);
        -- I am SAME for the whole class rooted in FOO
    procedure A (THIS : in FOO) is abstract;
        -- I have an implementation in each instance of the class except
        -- for the abstract ones like FOO.
end FOOS;

package body FOOS is
   procedure P (THIS : in FOO'Class) is
   begin
      A (THIS);
         -- I do not know what kind of FOO is THIS. So I
         -- dispatch to A according to the tag of THIS.
   end P;
end FOOS;

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



  parent reply	other threads:[~2009-11-20 13:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20 13:15 What makes a procedure call 'dispatching' in Ada? Markus Schoepflin
2009-11-20  9:31 ` stefan-lucks
2009-11-20 14:10   ` Niklas Holsti
2009-11-20 13:27 ` Dmitry A. Kazakov [this message]
2009-11-20 13:43   ` Markus Schoepflin
2009-11-20 13:54     ` RasikaSrinivasan@gmail.com
2009-11-20 13:58     ` Markus Schoepflin
2009-11-20 14:19       ` Niklas Holsti
2009-11-21 14:07       ` Peter C. Chapin
2009-11-20 14:00     ` Niklas Holsti
2009-11-20 14:10     ` Dmitry A. Kazakov
2009-11-20 13:56 ` Niklas Holsti
2009-11-20 14:31   ` Dmitry A. Kazakov
2009-11-20 15:00     ` Niklas Holsti
2009-11-20 18:44       ` Dmitry A. Kazakov
2009-11-20 20:09         ` Niklas Holsti
2009-11-20 20:59           ` Dmitry A. Kazakov
2009-11-20 14:54 ` Ludovic Brenta
replies disabled

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