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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e9c183f3911c2d73 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.131.75 with SMTP id w11mr470313bks.0.1334394062832; Sat, 14 Apr 2012 02:01:02 -0700 (PDT) Path: h15ni122016bkw.0!nntp.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.szaf.org!feeder.erje.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 14 Apr 2012 10:43:53 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Dynamic binding References: <71a9f655-9441-4083-9761-80d7df892277@w5g2000vbv.googlegroups.com> In-Reply-To: <71a9f655-9441-4083-9761-80d7df892277@w5g2000vbv.googlegroups.com> Message-ID: <4f8938c6$0$7624$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 14 Apr 2012 10:43:50 CEST NNTP-Posting-Host: b18c4458.newsspool1.arcor-online.net X-Trace: DXC=bmTh9DVhQ_^V;Ef1`Jk54\ic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgR8Y9d<0BE=7WPCY\c7>ejVXaKQc@agRXA]K\PoX33dhWY X-Complaints-To: usenet-abuse@arcor.de X-Received-Bytes: 3629 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-04-14T10:43:50+02:00 List-Id: On 13.04.12 22:11, Katarina Olsson wrote: > the output will be the following on stdout: > >>> parent a >>> child b > > I have now attempted to reproduce the corresponding case in Ada. If I > create a tagged record Object in package Parent, and then the > corresponding procedures (or functions): > > procedure A (This : access all Object); > procedure B (This : access all Object); Just to make sure: 1) "access all Object" is not a pointer to "Object or a type derived from Object". Just to Object. 2)It is, however, a pointer to something that is already passed by reference: O-O types in Ada are pass-by-reference types. (The "all" part requests that the object of type "Object" could have been allocated from the heap (using "new"), or be declared on the stack (without new).) > ... then in package Child, I create a new Parent.Object: > > type Object is new Parent.Object with null record > > ...and override the B method: > > overrides > procedure B (This : access all Object) > > This should correspond to the previous java case, shouldn't it? The procedures will logically correspond to the Java methods if you turn the This parameters into "Ada style" O-O references, i.e., do not introduce pointers to references. There will be dispatching if requested. The request is expressed, for objects X of type "T, or derived from T", by writing X : T'Class -- declaring a class-wide when declaring objects, and T'Class (X) -- converting to class-wide when passing objects so that dispatching take place, dispatching based on X's actual tag. (T'Class denotes a class of types, not a class of objects.) package O_O is type Parent is tagged null record; procedure A (This: in Parent); procedure B (This: in Parent); type Child is new Parent with record N : Natural; end record; overriding procedure B (This: in Child); end O_O; with Ada.Text_IO; package body O_O is use Ada.Text_IO; procedure A (This: in Parent) is begin Put_Line ("parent a"); B (Parent'Class (This)); end A; procedure B (This: in Parent) is begin Put_Line ("parent b"); end B; overriding procedure B (This: in Child) is begin Put_Line ("child b"); end B; X : Parent'Class := Child'(Parent with N => 42); begin A (X); end O_O; $ ./o_o parent a child b $