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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a370fcbf5c4dae94 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: How to?: Re-dispatching within an inherited method Date: 1999/08/09 Message-ID: <7onk8f$2qg@hobbes.crc.com>#1/1 X-Deja-AN: 510830525 References: <37AF0ADE.3D80FEB3@hiwaay.net> Organization: Coleman Research Corporation X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700 Newsgroups: comp.lang.ada Date: 1999-08-09T00:00:00+00:00 List-Id: Anthony E. Glover wrote in message <37AF0ADE.3D80FEB3@hiwaay.net>... >Is it possible to re-dispatch a method call within an inherited method? >For example: > >package A defines a type widget that has methods widget_size and run_widget. >package B defines a type bigwidget that has an overriding method for >widget_size, but >inherits the run_widget method without modification. >Within package A, run_widget makes a call to widget_size. Is it >possbile to force >a re-dispatch such that the appropriate widget_size method gets called based >on the object passed into run_widget? > Yes. You need to type convert the actual parameter in the call to Widget'Class to make the call a dispatching call. See RM 95 3.9.2 (1, 5). As in the example: with Ada.Text_IO; package body A is procedure Run_Widget (The_Widget : Widget'Class) is begin Ada.Text_IO.Put_Line ("in Run_Widget (The_Widget : Widget): Size =" & Positive'Image (Widget_Size (Widget'Class (The_Widget)))); end Run_Widget; function Widget_Size (The_Widget : Widget) return Positive is begin return 1; end Widget_Size; end A; package A is type Widget is tagged null record; procedure Run_Widget (The_Widget : Widget'Class); function Widget_Size (The_Widget : Widget) return Positive; end A; package body B is function Widget_Size (The_Widget : BigWidget) return Positive is begin return 10; end Widget_Size; end B; with A; package B is type BigWidget is new A.Widget with null record; function Widget_Size (The_Widget : BigWidget) return Positive; end B; with A; with B; procedure Glover is The_Widget : A.Widget; The_BigWidget : B.BigWidget; begin A.Run_Widget (The_Widget); A.Run_Widget (The_BigWidget); end Glover;