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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-25 17:00:18 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada References: <21836716.smDW2dK3SM@linux1.krischik.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 26 Nov 2003 01:00:18 GMT NNTP-Posting-Host: 63.184.9.194 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1069808418 63.184.9.194 (Tue, 25 Nov 2003 17:00:18 PST) NNTP-Posting-Date: Tue, 25 Nov 2003 17:00:18 PST Xref: archiver1.google.com comp.lang.ada:2949 Date: 2003-11-26T01:00:18+00:00 List-Id: Ekkehard Morgenstern wrote: > Both the Ada Rationale and the Guide for C/C++ programmers say that > you have to declare the first parameter of a procedure or the return > value of a function to be of the class-wide type of the class to get > the dynamic runtime dispatching behaviour from Ada (like virtual > functions in C++). Not at all. With a class-wide type, you get NO dispatching when you call the subprogram; you may get dispatching from calls made by the subprogram. To get dispatching, you need to call a parent type's operation with a value with a tag not known at compile time. Example: package A is type Parent is tagged null record; procedure Op (P : in Parent); -- Op 1 function Get return Parent'Class; end A; package A.B is type Child is new Parent with null record; procedure Op (P : in Child); -- Op 2 end A.B; ... with A; ... A.Op (P => A.Get); -- Dispatches to the correct Op -- Jeff Carter "Sheriff murdered, crops burned, stores looted, people stampeded, and cattle raped." Blazing Saddles 35