From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: dispatching query
Date: 1998/02/05
Date: 1998-02-05T00:00:00+00:00 [thread overview]
Message-ID: <34DA1D7C.575@gsfc.nasa.gov> (raw)
In-Reply-To: 34CFD22D.1D20CEA9@dsto.defence.gov.au
Mark Rutten wrote:
>
> Is it only possible to dispatch on subprograms which can be inherited
> (i.e. specified in the same declarative block)?
This is correct; see LRM 3.9.2. A dispatching operation is a primitive
operation, which is declared in the same block as the tagged type.
>
> e.g.
>
> package messages is
>
> type message is abstract tagged null record;
> type message_ptr is access all message'Class;
>
> procedure copy(msg: access message) is abstract;
>
> end messages;
>
> Then (in some other package) I declare a type (or several types) which
> extend message. What I would like to do is to define a set of procedures
> in a third package (separate to the declarations of the types) which can
why do you want the operations in a third package?
If you want to hide the operations from some parts of the application,
you can declare the operations in the private part of the package spec.
> be dispatched upon
>
> e.g.
>
> procedure handle(msg: access boolean_message);
> procedure handle(msg: access integer_message);
>
> where boolean_message and integer_message have been inherited from
> message and are declared in the second package. Then I would like to
> call
>
> handle(msg);
>
> (msg of type message_ptr) and have this dispatch on the above two
> procedures.
>
> I guess what I'm really trying to do is to replace what might be a case
> statement over the different inherited types with this set of
> procedures. I've tried the above with gnat3.09 on Solaris, but it
> complains at having too many choices when trying to resolve the
> procedure call, rather than recognising a dispatchable operation. Is
> there a way around this?
As you guessed, you must declare dispatching operations with the types.
--
- Stephe
prev parent reply other threads:[~1998-02-05 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <34CFD22D.1D20CEA9@dsto.defence.gov.au>
1998-02-04 0:00 ` dispatching query John English
1998-02-05 0:00 ` Stephen Leake [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