From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,db28129c6779d52b,start X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: dispatching query Date: 1998/02/05 Message-ID: <34DA1D7C.575@gsfc.nasa.gov>#1/1 X-Deja-AN: 322406900 Content-Transfer-Encoding: 7bit References: <34CFD22D.1D20CEA9@dsto.defence.gov.au> Mime-Version: 1.0 Reply-To: Stephen.Leake@gsfc.nasa.gov Content-Type: text/plain; charset=us-ascii Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1998-02-05T00:00:00+00:00 List-Id: 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