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!news3.google.com!feeder.news-service.com!news2.euro.net!fi.sn.net!newsfeed2.fi.sn.net!news.song.fi!not-for-mail Date: Fri, 20 Nov 2009 16:10:54 +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: <4b06a394$0$6270$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 81.17.205.61 X-Trace: 1258726292 news.tdc.fi 6270 81.17.205.61:35187 X-Complaints-To: abuse@tdcnet.fi Xref: g2news1.google.com comp.lang.ada:8174 Date: 2009-11-20T16:10:54+02:00 List-Id: > On Fri, 20 Nov 2009, Markus Schoepflin wrote: > > >> ---%<--- >> package FOOS is >> >> type FOO is abstract tagged null record; >> >> procedure P (THIS : in FOO); > > -------> replace by > procedure P (THIS : in FOO'Class); > >> procedure A (THIS : in FOO) is abstract; >> >> end FOOS; >> >> package body FOOS is >> >> procedure P (THIS : in FOO) > > -------> replace by > procedure P (THIS : in FOO'Class); > >> 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? >> >> TIA, >> Markus stefan-lucks@see-the.signature wrote: > If Foo is a tagged type, then > "procedure A(This: [in] [out] Foo)" > > expects *exactly* the same type as the actual parameter. If you want > "either type Foo or any of its object-oriented children" you write > > "procedure B(This: [in] [out] Foo'Class)". > > In your case, Foo is an abstract tagged type. As much as I seem to > understand Ada, there is no way to actually call procedure A -- because > you can't have any actuals of an abstract type. (Hey you guys out there, > am I wrong?) There is no way to call A on an object of (apparent) type FOO because A is declared as abstract for FOO. The compiler very correctly says that such a call is impossible. But you can call the overriding (concrete) implementation of A for the actual type of THIS (some non-abstract type derived from FOO) by converting to class-wide to force dispatching: A (FOO'Class (THIS)); > If I am right, it is very regrettable that the compiler doesn't issue a > warning when compiling "procedure A(This: [in] [out] Foo)" for an abstract > type Foo ... perhaps better, a revised Ada should prohibit that. There is no reason for such a warning because defining A in this way is legal and useful, as long as you convert the parameter to FOO'Class when you call it. You can consider the name A (of the abstract operation) a kind of place-holder for all the concrete implementations of A for derived types. But Dmitry probably thinks that there should be warning of the form "Bad design! Naughty!" :-) -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .