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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,366b213c4abb1039 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!emea.uu.net!fi.sn.net!newsfeed2.tdcnet.fi!news.song.fi!not-for-mail Date: Fri, 20 Nov 2009 15:56:50 +0200 From: Niklas Holsti Organization: Tidorum Ltd User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: What makes a procedure call 'dispatching' in Ada? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4b06a048$0$26319$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 81.17.205.61 X-Trace: 1258725448 news.tdc.fi 26319 81.17.205.61:50985 X-Complaints-To: abuse@tdcnet.fi Xref: g2news1.google.com comp.lang.ada:8170 X-Original-Bytes: 3066 Date: 2009-11-20T15:56:50+02:00 List-Id: Markus Schoepflin wrote: > Hello, > > 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; No problems there (well, Dmitry will have philosophical objections to this design :-) > package body FOOS is > > procedure P (THIS : in FOO) > is > begin > A (THIS); At this point, the compiler knows that THIS is a FOO object, or is to be seen as a FOO object. But you have said that the procedure A on FOO is abstract -- not implemented -- so you cannot call it. I assume that your intention is to call the procedure A that is implemented (overriden) for the actual object THIS, which is of some type derived from FOO .. some type in FOO'Class for which you have implemented A. To do so, you must ask the compiler to make this call dispatching, by converting the parameter to FOO'Class: A (FOO'Class (THIS)); This is called a "redispatching" call, because the procedure P may have been reached as the result of a dispatching call on P, and now we are asking to dispatch again. One way to understand this is that in Ada by default calls are statically bound, not run-time bound (dispatching). Only calls that have parameters of class type are dispatching. Dmitry has philosophical objections to redispatching, which is why he suggests that you should declare P with a class-type parameter THIS in the first place, so that A (THIS) will dispatch. Either will work, but in Dmitry's approach you cannot override P for derived types, because it is then a class-wide operation, not a primitive operation of FOO. In both approaches you can override A for derived types (and you must override it because it is abstract in FOO). -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .